如果 parent 进程收集终止状态失败一次,内核 re-try 再次发送 SIGCHLD
Kernel re-try sending SIGCHLD again if parent process fails once to collect termination status
当parent进程无法收集系统(内核)通过SIGCHLD
发送的child进程的终止状态时,child进程成为僵尸过程。
系统是否再次尝试为 parent 进程发送此进程终止状态以尝试收集其 child 的退出状态?
会不会出现这种情况,僵尸进程会从进程中移除table?
parent 是否再次尝试读取其 child 的终止状态?
When a parent process fails to collect the termination status of its
child process send by system(Kernel) through SIGCHLD, the child
process becomes a Zombie process.
这在技术上是不准确的。僵尸进程不是其 parent 无法获取终止状态的进程 - 相反,它是一个已经终止但未获得其终止状态的进程。
因此,在 parent 中交付 SIGCHLD
时,该进程已经是僵尸进程,因为它已终止,但终止状态未获得。
重点是,SIGCHLD
在这里有点无关紧要:要么 parent 获得 child 的终止状态,要么没有,在这种情况下 child 仍然是僵尸。
Does System try again to send this process termination status for the
parent process to try collecting the exit status of its child?
没有。 SIGCHLD
仅交付一次。如果 parent 没有在信号处理程序中获得僵尸的终止状态(这不是必需的),那么它要么稍后这样做(在程序代码中的某个点),要么不这样做而终止(在在这种情况下,僵尸的 parent 成为 init 进程;init 定期获取孤儿 children 的状态来清理僵尸)。
Will such thing happen and zombie process will be removed from the
process table?
僵尸进程使用的资源在 parent 获取退出状态后立即释放。
OTOH,如果 SIGCHLD
被显式忽略(即通过将其配置更改为 SIG_IGN
),将不会有僵尸进程,因为忽略 SIGCHLD
可以防止这种情况发生。但是,将无法获取终止状态。
来自man 2 sigaction
:
POSIX.1-1990 disallowed setting the action for SIGCHLD to SIG_IGN.
POSIX.1-2001 allows this possibility, so that ignoring SIGCHLD can be
used to prevent the creation of zombies (see wait(2)).
最后:
Does the parent try again to read this termination status of its
child?
一般来说,一旦parent收集到僵尸的退出状态,再次尝试收集就会出错。正如我之前所说,获取僵尸的终止状态将释放僵尸正在使用的所有资源,因此您不能多次获取终止状态。
此规则的例外情况是 WNOWAIT
标志传递给 waitid(2)
。该标志收集 child 的终止状态并使其处于可等待状态;可以在同一进程上再次使用稍后的调用来获取终止状态。
当parent进程无法收集系统(内核)通过SIGCHLD
发送的child进程的终止状态时,child进程成为僵尸过程。
系统是否再次尝试为 parent 进程发送此进程终止状态以尝试收集其 child 的退出状态?
会不会出现这种情况,僵尸进程会从进程中移除table?
parent 是否再次尝试读取其 child 的终止状态?
When a parent process fails to collect the termination status of its child process send by system(Kernel) through SIGCHLD, the child process becomes a Zombie process.
这在技术上是不准确的。僵尸进程不是其 parent 无法获取终止状态的进程 - 相反,它是一个已经终止但未获得其终止状态的进程。
因此,在 parent 中交付 SIGCHLD
时,该进程已经是僵尸进程,因为它已终止,但终止状态未获得。
重点是,SIGCHLD
在这里有点无关紧要:要么 parent 获得 child 的终止状态,要么没有,在这种情况下 child 仍然是僵尸。
Does System try again to send this process termination status for the parent process to try collecting the exit status of its child?
没有。 SIGCHLD
仅交付一次。如果 parent 没有在信号处理程序中获得僵尸的终止状态(这不是必需的),那么它要么稍后这样做(在程序代码中的某个点),要么不这样做而终止(在在这种情况下,僵尸的 parent 成为 init 进程;init 定期获取孤儿 children 的状态来清理僵尸)。
Will such thing happen and zombie process will be removed from the process table?
僵尸进程使用的资源在 parent 获取退出状态后立即释放。
OTOH,如果 SIGCHLD
被显式忽略(即通过将其配置更改为 SIG_IGN
),将不会有僵尸进程,因为忽略 SIGCHLD
可以防止这种情况发生。但是,将无法获取终止状态。
来自man 2 sigaction
:
POSIX.1-1990 disallowed setting the action for SIGCHLD to SIG_IGN.
POSIX.1-2001 allows this possibility, so that ignoring SIGCHLD can be used to prevent the creation of zombies (see wait(2)).
最后:
Does the parent try again to read this termination status of its child?
一般来说,一旦parent收集到僵尸的退出状态,再次尝试收集就会出错。正如我之前所说,获取僵尸的终止状态将释放僵尸正在使用的所有资源,因此您不能多次获取终止状态。
此规则的例外情况是 WNOWAIT
标志传递给 waitid(2)
。该标志收集 child 的终止状态并使其处于可等待状态;可以在同一进程上再次使用稍后的调用来获取终止状态。