使用fork()创建的子进程在父进程被杀死时会自动终止吗? [英] Are child processes created with fork() automatically killed when the parent is killed?

查看:1031
本文介绍了使用fork()创建的子进程在父进程被杀死时会自动终止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C / C ++中使用 fork()创建子进程。

当父进程结束时原因)我想要所有的子进程也被杀死。

是由系统自动完成的吗?



感谢。





$ b

预先存在的类似问题:




解决方案

否。如果父进程被杀死,子进程成为init进程的子进程(进程id为1,内核作为第一个用户进程启动)。



init进程定期检查新的子进程,如果它们已经退出,则将其杀死(从而释放由它们的返回值分配的资源)。



问题已经在质量答案中讨论过了:
http://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits


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:

解决方案

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 kills them if they have exited (thus freeing resources that are allocated by their return value).

The question was already discussed with quality answers here: http://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits

这篇关于使用fork()创建的子进程在父进程被杀死时会自动终止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆