|
#1
|
|||
|
|||
|
can you explain to me why I call fork twice can avoid zombie state?
and I can call fork twice which child process I can avoid to become zombie ?the first or the second child process? |
|
#2
|
|||
|
|||
|
The reason to fork() twice is so that the grandchild becomes an orphan (since its
parent, the child of the original process, will exit)... Therefore, the original parent process no longer has any relation to the running grandchild, so it won't get stuck needing to reap it when it dies... Instead, the grandchild becomes an adopted child of "init" (process 1) when its parent (the first child of the original parent) exits, and so init becomes responsible for reaping it (which it will) and preventing it from becoming a zombie... |
|
#3
|
|||
|
|||
|
are there any other methods can avoid the occurence of the zombie process except call wait()?
can you give me some some examples? |
|
#4
|
|||
|
|||
|
On some systems, simply ignoring SIGCHLD will prevent zombies, as well... That's
not portable behavior, though... The most common method of preventing zombies is probably a simple waitpid() reaper installed as a SIGCHLD handler... Or, the double-fork() to abandon the grandchild to init, as you mentioned... |
![]() |
| Thread Tools | |
| Display Modes | |
|
|