开发者

Why am I getting an unexpected return code?

开发者 https://www.devze.com 2023-01-04 01:29 出处:网络
I have a Perl script with the following code. ... $kill = 1; $exit = 0; `kill -9 $pid >& /dev/null`;

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?


From here:

The exit() function does not always exit immediately. It calls any defined END routines first, but these END routines may not themselves abort the exit. Likewise any object destructors that need to be called are called before the real exit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号