Skip to content
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 #5063

Closed
victorhurdugaci opened this issue Feb 9, 2016 · 18 comments
Closed

A way to graceful shutdown a process chain #5063

victorhurdugaci opened this issue Feb 9, 2016 · 18 comments
Labels
Bug
Milestone

Comments

@victorhurdugaci
Copy link

@victorhurdugaci 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
Copy link
Author

@victorhurdugaci 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
Copy link
Author

@victorhurdugaci 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
Copy link
Author

@victorhurdugaci 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
Copy link
Author

@victorhurdugaci victorhurdugaci commented Feb 18, 2016

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

@davidfowl
Copy link
Contributor

@davidfowl davidfowl commented Feb 18, 2016

@stephentoub new API? Process.KillAll()?

@blackdwarf
Copy link

@blackdwarf blackdwarf commented Feb 23, 2016

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

@victorhurdugaci
Copy link
Author

@victorhurdugaci 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
Copy link

@muratg muratg commented Feb 23, 2016

👀

@victorhurdugaci
Copy link
Author

@victorhurdugaci 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
Copy link
Contributor

@brthor brthor commented Mar 31, 2016

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

@victorhurdugaci
Copy link
Author

@victorhurdugaci 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
Copy link
Contributor

@vijayrkn vijayrkn commented Jun 3, 2016

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

@TheRealPiotrP
Copy link
Contributor

@TheRealPiotrP TheRealPiotrP commented Jul 28, 2016

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

@muratg
Copy link

@muratg muratg commented Jul 28, 2016

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

@sandorfr
Copy link

@sandorfr 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
Copy link
Member

@omajid omajid commented Aug 15, 2017

@bgribaudo
Copy link

@bgribaudo bgribaudo commented Dec 11, 2019

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

@muratg
Copy link

@muratg muratg commented Dec 11, 2019

@bgribaudo perfect! Thanks!

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet