Sdk: A way to graceful shutdown a process chain

Created on 9 Feb 2016  路  18Comments  路  Source: dotnet/sdk

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

Bug

Most helpful comment

@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.

All 18 comments

Options so far:

  1. Have an API exposed from CLR to kill a process tree
  2. Have the cli create a file or write to std out the child process ID
  3. Crazy idea: run spawns a process that watches itself and the child process. If one of them dies, it kills the other.
  4. Crazy idea: make corehost aware of the parent process and stop if the parent is gone

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!

Was this page helpful?
0 / 5 - 0 ratings