Created
October 17, 2014 07:12
-
-
Save yohhoy/484f82617965a09a7202 to your computer and use it in GitHub Desktop.
kill process tree(process group) on WIndows/C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void KillProcessTree(System.Diagnostics.Process process) | |
{ | |
string taskkill = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "taskkill.exe"); | |
using (var procKiller = new System.Diagnostics.Process()) { | |
procKiller.StartInfo.FileName = taskkill; | |
procKiller.StartInfo.Arguments = string.Format("/PID {0} /T /F", process.Id); | |
procKiller.StartInfo.CreateNoWindow = true; | |
procKiller.StartInfo.UseShellExecute = false; | |
procKiller.Start(); | |
procKiller.WaitForExit(1000); // wait 1sec | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useless. By doing it using windows's executables, you don't get full control over the output, etc. Sometimes, you want to know if the process that you executed the "termination" function on, died by the function, process, or it died by itself because other process children/thread died. Basically, you have a veery limited amount of control.