kscaldef has asked for the wisdom of the Perl Monks concerning the following question:
All the documentation I've encountered claims that $? should be non-negative (more specifically, an unsigned 16-bit integer). However, I have some code where $? is getting set to -1 and I have no idea what this means.
The code in question spawns a bunch of worker children, with a SIG{CHLD} handler to keep track of when they all finish, which looks like this (with some added debugging statements):
sub REAPER { while ((my $pid = waitpid(-1, &WNOHANG)) > 0) { if (WIFEXITED($?)) { } elsif (WIFSIGNALED($?)) { print "$?\n", $? >> 8, "\n", $? & 127, "\n"; print( "child exited with signal: ", WTERMSIG($?), "\n"); } elsif (WIFSTOPPED($?)) { print "child stopped????\n"; next; } else { print "hmmm\n"; } delete $children{$pid}; $children--; print "$children children running\n"; } $SIG{CHLD} = \&REAPER; #probably not needed, but paranoia }
Occasionally, this produces output like:
... 7 children running 6 children running -1 72057594037927935 127 child exited with signal: 127 5 children running ...
I think that there might be some sort of race condition or reentrancy problem involved, as when I purposely space the children out so that their exits are well seperated, this never happens. However, the normal operation is for them to do very similar amounts of work, and therefore finish very close to one another. However, my understanding is that while the SIGCHLD handler is executing, any other SIGCHLD should be blocked (thus the while loop), so I wouldn't have thought this would be an issue.
So, I ask you, what is going on here? Is the documentation incorrect, am I screwing something up, or is this a bug in perl? I'm using 5.8.0, btw.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $? is -1???
by davidj (Priest) on Jun 20, 2004 at 04:16 UTC | |
by kscaldef (Pilgrim) on Jun 20, 2004 at 06:13 UTC | |
Re: $? is -1???
by holo (Monk) on Jun 20, 2004 at 19:22 UTC | |
by kscaldef (Pilgrim) on Jun 20, 2004 at 19:53 UTC | |
Re: $? is -1???
by dga (Hermit) on Jun 21, 2004 at 13:39 UTC | |
by kscaldef (Pilgrim) on Jun 21, 2004 at 15:52 UTC | |
Re: $? is -1???
by bluto (Curate) on Jun 21, 2004 at 19:22 UTC | |
by kscaldef (Pilgrim) on Jun 21, 2004 at 21:59 UTC | |
by bluto (Curate) on Jun 21, 2004 at 22:35 UTC | |
by kscaldef (Pilgrim) on Jun 21, 2004 at 23:00 UTC | |
by bluto (Curate) on Jun 21, 2004 at 23:02 UTC |