O
Oliver
hi all -
I'm struggling to reap my children.
I have a parent process that is forking to do work in parallel.
I need to keep track and manage the number of child processes.
I am doing this by creating a communication link between child and
parent using "socketpair" - the idea being that the parent can check
on the state of the children by checking the state of the handle to
the child (* comments/crits. on this approach welcome).
all this avoids signals - yipee!! - will nearly - I find I have to
have a signal handler anyway to read my children.
I don't really want to do this - so I have tried: $SIG{CHILD} =
'IGNORE';
... but whatever I do I seem to frequently (but not always) get
children hanging around after the parent dies.
I've tried every variant on the usual reaper code imaginable - this
sort of thing:
sub REAPER {
my $child;
print "reaping - \n";
while ((my $waitedpid = waitpid(-1,WNOHANG)) > 0) {
print "reaped $waitedpid" . ($? ? " with exit $?" : '') .
"\n";
}
$SIG{CHLD} = \&REAPER; # loathe sysV
}
I've also tried to make sure that the handles created by socketpair
are closed/undefined - but no joy.
any ideas out there?
cheers,
Oli
I'm struggling to reap my children.
I have a parent process that is forking to do work in parallel.
I need to keep track and manage the number of child processes.
I am doing this by creating a communication link between child and
parent using "socketpair" - the idea being that the parent can check
on the state of the children by checking the state of the handle to
the child (* comments/crits. on this approach welcome).
all this avoids signals - yipee!! - will nearly - I find I have to
have a signal handler anyway to read my children.
I don't really want to do this - so I have tried: $SIG{CHILD} =
'IGNORE';
... but whatever I do I seem to frequently (but not always) get
children hanging around after the parent dies.
I've tried every variant on the usual reaper code imaginable - this
sort of thing:
sub REAPER {
my $child;
print "reaping - \n";
while ((my $waitedpid = waitpid(-1,WNOHANG)) > 0) {
print "reaped $waitedpid" . ($? ? " with exit $?" : '') .
"\n";
}
$SIG{CHLD} = \&REAPER; # loathe sysV
}
I've also tried to make sure that the handles created by socketpair
are closed/undefined - but no joy.
any ideas out there?
cheers,
Oli