in reply to system() returns -1 with $SIG{CHLD}?

under the hood, system should be something similar to:
sub system { my $pid = fork; if (!$pid) { exec @_; exit(-1); } while (1) { if (waitpid($pid, \$?, 0) > 0) { # supposing this calls the C wait +pid! return $? } if ($! == EINTR) { run_signal_handlers(); next; } return -1; } }
Setting a signal handler for SIG{CHLD} probably interrupts the waitpid call, your handler is run and as it calls wait(), the process just run gets reaped.

When waitpid is called again, it finds that the child it should be waiting for has been already reaped, and so, returns an error.

If you check $! it should contain the value ECHILD.

update: I think this could be considered a perl bug, so report it to p5p!