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?
先前存在的类似问题:
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?
先前存在的类似问题:
否.如果父进程被终止,子进程将成为init进程的子进程(进程id为1,由内核作为第一个用户进程启动).
init进程定期判断新的子进程,并等待它们(从而释放由其返回值分配的资源).
这里已经讨论了这个问题,并给出了高质量的答案: