in reply to Tallying results from Forking processes...
According to the docs for wait and waitpid, the status of the child process is returned in $?. Thus, your child can exit with a status code to indicate whether it succeeded, and the parent can use that to determine whether or not to increment $avail.
Here's a quick example based on some code from perlipc. (Please note that prior to 5.6.0 the relevant code sample in perlipc omitted the > 0 in the while condition.)
#!/usr/local/bin/perl -w use strict; use POSIX ":sys_wait_h"; my $avail; sub REAPER { my $child; while ($child = waitpid(-1,&WNOHANG()) > 0) { $avail += ! $?; # 0 means success, non-zero means failure } $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER; for (0..2,0..2) { if (fork) { } else { exit $_; } } print "$avail\n";
|
|---|