http://www.perlmonks.org?node_id=197500

Jonathan has asked for the wisdom of the Perl Monks concerning the following question:

I have a process that runs as a daemon forking off child processes when requests come in. To control zombies I have the standard
# Install signal handler for child processes $SIG{'CHLD'} = sub { while (waitpid(-1,WNOHANG) > 0) {} };
However, the child processes then have to make a system call and I need to trap the exit code eg..
my $res = system $cmd, $arg; unless ($res == 0) { ... }
$? now contains -1 and $! 'No child processes', I understand that this is because of my $SIG{'CHLD'} handler. But how can I get the true exit code and message? I've tried 'local $SIG{'CHLD'} = '' prior to the sys call and that seems to work but looks very clumsy.

What is the best way to get at the exit code?