How can I cause a child process to exit when the parent does?

后端 未结 9 2000
一生所求
一生所求 2020-11-27 16:07

I am launching a child process with ProcessBuilder, and need the child process to exit if the parent process does. Under normal circumstances, my code is stopping the child

9条回答
  •  爱一瞬间的悲伤
    2020-11-27 16:32

    There is no tie between a child process and its parent. They may know each others process ID, but there's no hard connection between them. What you're talking about a orphan process. And it's an OS level concern. Meaning any solution is probably platform dependent.

    About the only thing I can think of is to have the child check its parents status periodically, exiting if the parent's shutdown. I don't think this would be all that reliable though.

提交回复
热议问题