dotnet run creates 2 processes: (1) dotnet and (2) the app being run.
If you kill dotnet the app being run (the exe) is orphaned.
For dotnet watch we need a way to tell the parent process to terminate the child processes before exiting.
Not sure if this should be addressed at the CLI level, or lower..
cc @piotrpMSFT
Options so far:
cc @davidfowl
This is a much broader issue. If you do "dotnet run" and kill the process from Task Manager, you have the same issue. Maybe corehost should watch for the parent?
I have to mark this as blocking. Our tests fail because there are processes left orphaned and subsequent compiles fail.
Removing the blocking flag. We found a workaround using taskkill/pkill
@stephentoub new API? Process.KillAll()?
@anurse @livarcocc wasn't there a discussion on how to solve this?
There's a workaround by invoking taskkill/pkill but it's hacky and it doesn't work everyone. For example nano server doesn't have taskkill
:eyes:
Just found out that pkill -TERM -P <id> kills only the first generation child of <id>. If you want to kill an entire tree you have to recursively pgrep or something similar and then kill. cc @stephentoub 
@victorhurdugaci did you make any progress in solving this issue? cc @Sridhar-MS is hitting a similar issue
I ended up writing a helper that kills a process tree. Not the perfect solution but it works for us. https://github.com/aspnet/Common/blob/dev/src/Microsoft.Extensions.Process.Sources/ProcessHelper.cs#L22
/cc @livarcocc
Similar issue : https://github.com/aspnet/Tooling/issues/537
It doesn't look like there is any remaining CLI work being tracked in this issue.
@piotrpMSFT What's the recommended way of doing this? (Killing a whole process tree, cross platform)
@muratg I'm wondering the same... Have you got an answer?
Would be nice to have an xplat process management API.
@muratg
What's the recommended way of doing this? (Killing a whole process tree, cross platform)
There's now a Process.Kill() overload for terminating the entire process tree.
@bgribaudo perfect! Thanks!
Most helpful comment
@muratg
There's now a Process.Kill() overload for terminating the entire process tree.