/// <summary> /// Kills the process(OR process group) by sending the signal SIGKILL /// in the current thread /// </summary> /// <param name="pid">Process id(OR process group id) of to-be-deleted-process</param> /// <param name="isProcessGroup">Is pid a process group id of to-be-deleted-processes /// </param> /// <param name="sleepTimeBeforeSigKill"> /// wait time before sending SIGKILL after /// sending SIGTERM /// </param> private static void SigKillInCurrentThread(string pid, bool isProcessGroup, long sleepTimeBeforeSigKill) { // Kill the subprocesses of root process(even if the root process is not // alive) if process group is to be killed. if (isProcessGroup || ProcessTree.IsAlive(pid)) { try { // Sleep for some time before sending SIGKILL Sharpen.Thread.Sleep(sleepTimeBeforeSigKill); } catch (Exception) { Log.Warn("Thread sleep is interrupted."); } if (isProcessGroup) { KillProcessGroup(pid); } else { KillProcess(pid); } } }
/// <summary>Send a specified signal to the process, if it is alive.</summary> /// <param name="pid">the pid of the process to signal.</param> /// <param name="signalNum">the signal to send.</param> /// <param name="signalName"> /// the human-readable description of the signal /// (for logging). /// </param> /// <param name="alwaysSignal">if true then send signal even if isAlive(pid) is false /// </param> private static void MaybeSignalProcess(string pid, int signalNum, string signalName , bool alwaysSignal) { // If process tree is not alive then don't signal, unless alwaysSignal // forces it so. if (alwaysSignal || ProcessTree.IsAlive(pid)) { SendSignal(pid, signalNum, signalName); } }