简体   繁体   English

如果父进程一次无法收集终止状态,则内核重试再次发送SIGCHLD

[英]Kernel re-try sending SIGCHLD again if parent process fails once to collect termination status

When a parent process fails to collect the termination status of a child process sent by system (Kernel) through SIGCHLD , the child process becomes a Zombie process. 当父进程无法收集系统(内核)通过SIGCHLD发送的子进程的终止状态时,该子进程将成为Zombie进程。

Does the system try again to send this process termination status for the parent process to try collecting the exit status of its child? 系统是否再次尝试为父进程发送该进程终止状态,以尝试收集其子进程的退出状态?

Will such thing happen and zombie process will be removed from the process table? 这样的事情会发生吗,僵尸进程将从进程表中删除?

Does the parent try again to read this termination status of its 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. 当父进程无法收集系统(内核)通过SIGCHLD发送的子进程的终止状态时,该子进程将成为Zombie进程。

This is not technically accurate. 这在技术上不准确。 A zombie process is not a process for which its parent failed to fetch the termination status - instead, it is a process that has already terminated but didn't have its termination status reaped. 僵尸进程不是其父级无法获取终止状态的进程,而是已经终止但未获得终止状态的进程。

So, by the time SIGCHLD is delivered in the parent, the process is already a zombie, because it terminated, but the termination status was not reaped. 因此,到在父级中传递SIGCHLD ,该进程已经是僵尸,因为它已终止,但未获得终止状态。

The point is, SIGCHLD is kind of irrelevant here: either the parent reaps the child's termination status, or it doesn't, in which case the child remains a zombie. 关键是, SIGCHLD在这里是无关紧要的:父母要么获得孩子的终止身份,要么没有,在这种情况下孩子仍然是僵尸。

Does System try again to send this process termination status for the parent process to try collecting the exit status of its child? 系统是否再次尝试为父进程发送该进程终止状态,以尝试收集其子进程的退出状态?

No. SIGCHLD is delivered exactly once. 不会SIGCHLD只交付一次。 If the parent doesn't reap the zombie's termination status in the signal handler (which is not required), then either it does so later (at some point in the program code), or it terminates without doing so (in that case, the zombie's parent becomes the init process; init periodically reaps the status of orphan children to clean up zombies). 如果父级没有在信号处理程序中获得僵尸的终止状态(这不是必需的),则它要么稍后执行(在程序代码中的某个时候),要么终止而不执行(在这种情况下,僵尸的父母成为初始化进程;初始化会定期获得孤儿的地位,以清理僵尸。

Will such thing happen and zombie process will be removed from the process table? 这样的事情会发生吗,僵尸进程将从进程表中删除?

The resources used by a zombie process are freed as soon as the parent reaps the exit status. 父进程获得退出状态后,僵尸进程使用的资源就会被释放。

OTOH, if SIGCHLD was explicitly ignored (ie by changing its disposition to SIG_IGN ), there will be no zombie processes because ignoring SIGCHLD prevents exactly that. OTOH,如果SIGCHLD被显式忽略(即,通过将其处置方式更改为SIG_IGN ),则不会有僵尸进程,因为忽略SIGCHLD阻止这种情况。 However, it will not be possible to get the termination status. 但是,将无法获得终止状态。

From man 2 sigaction : 从第man 2 sigaction

POSIX.1-1990 disallowed setting the action for SIGCHLD to SIG_IGN. POSIX.1-1990不允许将SIGCHLD的操作设置为SIG_IGN。

POSIX.1-2001 allows this possibility, so that ignoring SIGCHLD can be used to prevent the creation of zombies (see wait(2)). POSIX.1-2001允许这种可能性,因此可以忽略SIGCHLD来防止创建僵尸(请参阅wait(2))。

And finally: 最后:

Does the parent try again to read this termination status of its child? 父母会再次尝试读取其孩子的终止状态吗?

Generally, once the parent collects the exit status of a zombie, attempting to do it again will result in an error. 通常,一旦父母收集了僵尸的退出状态,再次尝试执行此操作将导致错误。 As I said before, reaping a zombie's termination status will free every resource that was being used by the zombie, so you can't fetch the termination status more than once. 如前所述,获取僵尸的终止状态将释放该僵尸正在使用的所有资源,因此您不能多次获取终止状态。

The exception to this rule is when the WNOWAIT flag is passed to waitid(2) . 该规则的例外是将WNOWAIT标志传递给waitid(2) This flag collects the termination status of a child and leaves it in a waitable state; 该标志收集子进程的终止状态,并将其置于等待状态。 a later call can be used again on the same process to get the termination status. 以后的呼叫可以在同一过程中再次使用以获取终止状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 父进程仅从其子进程接收到SIGCHLD一次或两次,而不管它多少次fork() - The parent-process only received SIGCHLD from its children once or twice, no mater how many times it fork() execl()-在父进程中:SIGCHLD被ps捕获 - execl()-ing in parent process: SIGCHLD caught by ps 父进程如何通过等待调用_exit的子进程获得终止状态 - How does parent process get the termination status through wait from a child process which calls _exit “ exit()”将“状态”发送给父进程或操作系统内核什么? - What does `exit()` send `status` to, the parent process or the OS kernel? 杀死派生的子进程会杀死SIGCHLD处理程序中的父进程 - Killing forked child process kills parent in SIGCHLD handler wait()SIGCHLD和退出状态 - wait() SIGCHLD and the exit status 当父进程在python中终止时如何避免进程终止 - How to avoid process termination when parent process terminates in python 子进程会在abort()上发送SIGCHLD吗? - Will a child process send SIGCHLD on abort()? 有什么方法可以在进程终止后或终止之前获取proc / pid / status - Is there any way to get proc/pid/status after termination or just before termination of the process 父进程终止后如何杀死所有子进程? - How to kill all child processes after parent process termination?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM