Let's say I have a C program which spawns some child processes using fork()
and exec()
. The parent keeps a list of the pid
s of its children. Once in a while, it tries wait
ing on them using WNOHANG
and informs the user if they have terminated.
The program then decides to exit. Must I explicitly kill
and then wait
on the remaining child processes so that they don't become zombies? According to Wikipedia:
"Zombie processes should not be confused with orphan processes: an orphan process is a process that is still executing, but whose parent has died. These do not become zombie processes; instead, they are adopted by init (process ID 1), which waits on its children."
So this suggests waiting is unnecessary. But what if the program's children have already become zombies, and the program exits before waiting on them? Basically, will a parent's child processes who are zombies always be reclaimed properly if the parent exits?