创建守护进程时执行双叉的原因是什么?我试图在python中创建一个守护进程。我找到了以下问题,它有一些好的资源,我现在正在跟踪,但我很好奇为什么需要一个双叉。我在谷歌(Google)周旋,发现了大量的资源,宣称这是必要的,但不是为什么。有人提到,这是为了防止守护进程获取控制终端。如果没有第二个叉子,它怎么能做到这一点?后果是什么?
3 回答

慕沐林林
TA贡献2016条经验 获得超9个赞
# Fork a second child and exit immediately to prevent zombies. This # causes the second child process to be orphaned, making the init # process responsible for its cleanup. And, since the first child is # a session leader without a controlling terminal, it's possible for # it to acquire one by opening a terminal in the future (System V-# based systems). This second fork guarantees that the child is no # longer a session leader, preventing the daemon from ever acquiring# a controlling terminal.
添加回答
举报
0/150
提交
取消