Pensei no wait -n
do Bash, mas ele não informou qual processo filho foi encerrado. Que tal um script Perl simples?
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
sub spawn(@) {
my $pid = fork();
die "fork: $!" if not defined $pid;
if ($pid == 0) {
exec @_ or die "exec: $!";
}
return $pid;
}
# Commands to run
my $p1 = spawn '/bin/bash -c "sleep 6; kill $$"';
my $p2 = spawn '/bin/bash -c "sleep 4; exit 4"';
print "spawned PIDs $p1 and $p2\n";
while ((my $child = waitpid(-1, 0)) > 0) {
my $code = $? >> 8;
my $status = $? & 0xff;
printf "child %d finished with exit code %d (status/sig %d)\n", $child, $code, $status;
}