in reply to $? is -1???

From perldoc -f system:

You can check all the failure possibilities by inspecting $? like this:

if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\ +n", ($? & 127), ($? & 128) ? 'with' : 'without +'; } else { printf "child exited with value %d\n", $? >> 8; }

Update: In the case of waitpid, this $? == -1 means that the child has been reaped automatically. I encountered this some time ago in a similar snippet. I do not know exactly why but a similar effect can be obtained by:

I cannot find the program I was working on but if I'm not mistaken, I got rid of all negative ones by simplifying the SIGCHILD handler. Store $? in the hash instead of testing it and test everything when all children are done.

Replies are listed 'Best First'.
Re^2: $? is -1???
by kscaldef (Pilgrim) on Jun 20, 2004 at 19:53 UTC
    I'm actually starting the child processes with fork(), not system(), and I do check to make sure the fork was successful. If the child exited right away, I might agree that this could be the explanation, but the problem child lives for just as long as all the others. (The script prints out "1 child running" ... "20 children running" ... time passes while children do work ... "19 children running" "18 children running" ... "0 children running", then exits). There is every indication that the child process does all the work it's supposed to, and no indication that it actually exits abnormally in any way.