in reply to Re^2: $SIG{CHILD} misses on zombies
in thread $SIG{CHILD} misses on zombies

George,

Are you doing the waitpid in a loop like I did? That should clear up all zombies that are waiting at that point.

sub child_handler { my $i; ++$i while -1 != waitpid -1, WNOHANG; print "Reaped $i children\n"; }
This may help you see how many children were waiting at a given time. You can also throw in more debugging such as log the output from ps or something to see the states of all processes on the system, then you can manually identify what is actually running, zombied, etc., both before and after the waitpid loop.

Replies are listed 'Best First'.
Re^4: $SIG{CHILD} misses on zombies
by gmantz (Initiate) on Sep 07, 2005 at 08:39 UTC
    Hello again,
    I wrote it exactly as you did. In fact i copied and pasted this code just to be sure. I still had dead children that the handler was unable to handle because they died exactly when the handler code was occupied with another child.
    Since i dont care about the pids of the dead processes i tried using wait() and i got it to work. The code looks like:
    while (($openforks > 0) && (wait())) { $openforks--; spawn(\@jobs); print "somebody died\n"; }

    In all the tests i ran, i reap the exact number of jobs that i spawned.
    Thanks for all the help though :)

    George