|Perl: the Markov chain saw|
Reaping Zombiesby dsb (Chaplain)
|on Feb 15, 2006 at 18:04 UTC||Need Help??|
dsb has asked for the
wisdom of the Perl Monks concerning the following question:
Hey all, I'm writing a script that needs to fork() and i want to be sure that I'm cleaning up all my zombies.
The code I'm using is:
Because I'm not all that familiar with waitpid() - or wait(), for that matter - I'm not clear on whether or not this code has the parent process hanging around until child processes are reaped. Also, I'm not sure if this is preventing the script from fork()'ing another process before previous children are reaped.
Finally, would I be better off just running the reaper() function w/o checking for zombies first, so that the script constantly is checking on child procs. The docs for waitpid() said that it could return 0 if child procs are still running, which seems like it might be helpful insofar as making sure child processes are reaped before the parent exits. This seems like it would account for any scenarios where the parent process finished it's logic and exits before receiving a CHLD signal.
UPDATE: The cookbook has a pretty good bit on reaping zombies. Three things cleared up in recipe 16.19 of The Cookbook First Edition.
This @ISA my( $cool ) %SIG