advacing lnux program zombie process [copy]

A zombie processis a process that has terminated but has not been cleaned up yet. It
is the responsibility of the parent process to clean up its zombie children.The wait
functions do this, too, so it’s not necessary to track whether your child process is still
executing before waiting for it. Suppose, for instance, that a program forks a child
process, performs some other computations, and then calls wait. If the child process
has not terminated at that point, the parent process will block in the waitcall until the
child process finishes. If the child process finishes before the parent process calls wait,
the child process becomes a zombie.When the parent process calls wait, the zombie
child’s termination status is extracted, the child process is deleted, and the waitcall
returns immediately.
What happens if the parent does not clean up its children? They stay around in the
system, as zombie processes.The program in Listing 3.6 forks a child process, which
terminates immediately and then goes to sleep for a minute, without ever cleaning up
the child process.

What happens when the main make-zombieprogram ends when the parent process
exits, without ever calling wait? Does the zombie process stay around? No—try
running psagain, and note that both of the make-zombieprocesses are gone.When a
program exits, its children are inherited by a special process, the initprogram, which
always runs with process ID of 1 (it’s the first process started when Linux boots).The
initprocess automatically cleans up any zombie child processes that it inherits.

原文地址:https://www.cnblogs.com/michile/p/2890541.html