use POSIX ':sys_wait_h'; # WNOHANG my %pids; # Parent's hash of child pids $SIG{CHLD} = sub { local ($?, $!); # Don't change $! or $? outside handler until (-1 == (my $pid = waitpid(-1, WNOHANG))) { return if $pid == 0; # Processes still running next unless delete $pids{$pid}; say "$pid exited with status $?"; } };