New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to graceful shutdown a process chain #1327

Closed
victorhurdugaci opened this Issue Feb 9, 2016 · 16 comments

Comments

Projects
None yet
9 participants
@victorhurdugaci
Contributor

victorhurdugaci commented Feb 9, 2016

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

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Feb 9, 2016

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

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Feb 9, 2016

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?

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Feb 10, 2016

I have to mark this as blocking. Our tests fail because there are processes left orphaned and subsequent compiles fail.

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Feb 18, 2016

Removing the blocking flag. We found a workaround using taskkill/pkill

@davidfowl

This comment has been minimized.

Collaborator

davidfowl commented Feb 18, 2016

@stephentoub new API? Process.KillAll()?

@blackdwarf blackdwarf added this to the RTM-March milestone Feb 23, 2016

@blackdwarf

This comment has been minimized.

Contributor

blackdwarf commented Feb 23, 2016

@anurse @livarcocc wasn't there a discussion on how to solve this?

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Feb 23, 2016

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

@muratg

This comment has been minimized.

Member

muratg commented Feb 23, 2016

👀

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Mar 1, 2016

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

@brthor

This comment has been minimized.

Contributor

brthor commented Mar 31, 2016

@victorhurdugaci did you make any progress in solving this issue? cc @Sridhar-MS is hitting a similar issue

@victorhurdugaci

This comment has been minimized.

Contributor

victorhurdugaci commented Mar 31, 2016

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

@vijayrkn

This comment has been minimized.

Collaborator

vijayrkn commented Jun 3, 2016

/cc @livarcocc
Similar issue : aspnet/Tooling#537

@TheRealPiotrP

This comment has been minimized.

Contributor

TheRealPiotrP commented Jul 28, 2016

It doesn't look like there is any remaining CLI work being tracked in this issue.

@muratg

This comment has been minimized.

Member

muratg commented Jul 28, 2016

@piotrpMSFT What's the recommended way of doing this? (Killing a whole process tree, cross platform)

@sandorfr

This comment has been minimized.

sandorfr commented Aug 14, 2017

@muratg I'm wondering the same... Have you got an answer?

Would be nice to have an xplat process management API.

@omajid

This comment has been minimized.

Member

omajid commented Aug 15, 2017

See also #7426

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment