子进程可以去&LT;&倒闭GT;没有它的父进程要死了吗? [英] Can a child process go <defunct> without its parent process dying?
问题描述
我发现我的回答,我设置了 SIGCHLD
并介绍了等
的信号处理程序的处理程序。这样一来,当父进程杀
一个子进程,这个处理程序被调用,它调用等待
来的收获的孩子。 - 动机是清除进程表项
I found my answer and I set up a signal handler for SIGCHLD
and introduced wait
in that handler. That way, whenever parent process kill
s a child process, this handler is called and it calls wait
to reap the child. - motive is to clear process table entry.
我仍然看到一些孩子去处理了几秒钟,即使没有它的父进程奄奄一息。 - 这是怎么的可能
I am still seeing some child processes going for a few seconds even without its parent process dying. - how is this possible?
我通过 PS
看到这个。 precisely PS -o用户,PID,PPID,命令-ax
和greping的父进程,子进程和解散。
I am seeing this via ps
. Precisely ps -o user,pid,ppid,command -ax
and greping for parent process, child process and defunct.
推荐答案
一个过程进行解散(僵尸),立即在退出(从信号,打电话退出
,回报从主
,等等)。它停留僵尸,直到等
'由其父D ON。
A process goes defunct (zombie) immediately upon exiting (from a signal, call to exit
, return from main
, whatever). It stays zombie until wait
'd on by its parent.
所以,所有的进程至少短暂成为退出时的僵尸。
So, all processes at least briefly become zombies upon exit.
如果父进程需要多一点(因为它是做其他工作,或者只是因为调度程序没有给它的CPU时间未定)之前调用等
,然后你会看到一个有点僵尸。如果父永远不会调用等
,那么当它最终退出,的init
(PID 1)将通过其zombied的孩子,和呼叫等
在他们身上。
If the parent process takes a bit (because it was doing other work, or just because the scheduler hasn't given it CPU time yet) before calling wait
, then you'll see the zombie for a bit. If the parent never calls wait
, then when it eventually exits, init
(pid 1) will adopt its zombied children, and call wait
on them.
这篇关于子进程可以去&LT;&倒闭GT;没有它的父进程要死了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!