1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/perl
sub sigchldHandler {
wait() ;
}
$SIG{CHLD} = \&sigchldHandler ;
my $pid = fork();
if ( $pid == 0 ) {
$Result=`ls -l`;
print "ReturnCode = $? \n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
If you'd like to manually inspect "system"'s failure, you can check
all possible failure modes by inspecting $? like this:
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}