On Wed, 2002-04-17 at 19:06, Ahmed Moustafa wrote:
> > You are better off trying
> >
> > $SIG{CHLD} = 'IGNORE';
> >
> > at the top of your program and seeing if zombies are left out there. If
> > so then you might want to use pop or shift like this
> >
> > waitpid shift @children while @children;
>
> Do I really need to hold the pid's of the kids process somewhere?
> Can't I do something like that <code>my $forked = fork; waitpid $forked,
> &WNOHANG;</code>?
> What do you think?
>
> Thanks,
>
> Ahmed
<DISCLAIMER>I am not an expert</DISCLAIMER>
<snip href="man 2 wait">
WNOHANG
which means to return immediately if no child has
exited.
</snip>
This says to me that wait returns (after doing nothing) if it cannot
find a child to reap. If I remember your application correctly you may
want to add a "wait &WNOHANG;" to your main loop removing the PIDs it
returns from your array (which might be better implemented as a hash
now) like this:
until ($terminate) { #main loop
#do stuff that forks off children and stores
#their PIDs in %running
my $child = wait &WNOHANG;
if ($child != -1) { #child just got reaped
#$running{PID} should == 1 if the PID is really a child
unless (delete $running{$child}) {
die "reaped a process I didn't know about";
}
}
}
#the main loop has exited, so we should check to see if there are
#any unreaped children
waitpid $_ for keys %running;
--
Today is Pungenday the 35th day of Discord in the YOLD 3168
Hail Eris!
Missile Address: 33:48:3.521N 84:23:34.786W
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]