I have a Perl script with the following code.
...
$kill = 1;
$exit = 0;
`kill -9 $pid >& /dev/null`;
...
print "kill=$kill exit=$exit\n";
if ($kill) {
exit $exit;
} else {
...
In summary, this script uses open3() to run a command. At some point, it kills the job and then the intention is that the script will exit with code 0. I inserted a print statement to show the values of variables $kill
and $exit
, which is shown below.
kill=1 exit=0
Since $kill
is 1, I would expect the script to exit with code 0 above, since $exit
is 0. However, the script exits with code 9, which is the signal sent to the child. Why is the Perl script exiting with the exit code of the child, instead of that which is given to the exit()
call?