Are child processes created with fork() automatically killed when the parent is killed?

空扰寡人 提交于 2019-11-26 08:08:16

问题


I\'m creating child processes with fork() in C/C++.
When the parent process ends (or is killed for some reason) I want all child processes to be killed as well.
Is that done automatically by the system? Or I have to do it myself?

Thanks.


Pre-existing similar questions:

  • How can I cause a child process to exit when the parent does?
  • How to make child process die after parent exits?

回答1:


No. If the parent is killed, children become children of the init process (that has the process id 1 and is launched as the first user process by the kernel).

The init process checks periodically for new children, and waits for them (thus freeing resources that are allocated by their return value).

The question was already discussed with quality answers here: How to make child process die after parent exits?



来源:https://stackoverflow.com/questions/395877/are-child-processes-created-with-fork-automatically-killed-when-the-parent-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!