简体   繁体   中英

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.

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.

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.

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.

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. 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. However, it will not be possible to get the termination status.

From 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)).

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) . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM