为什么Perl是$?为forked进程的退出代码返回错误的值?

Mik*_*ike 6 perl waitpid

考虑fork()的这个简单示例,然后等待子进程在Perl中死掉:

#!/usr/bin/perl

use strict;
use warnings;

if (fork() == 0) {
        exit(1);
}

waitpid(-1,0);

print $?;
Run Code Online (Sandbox Code Playgroud)

在Solaris 10上运行脚本我得到以下结果:

$ perl test.pl
256
Run Code Online (Sandbox Code Playgroud)

我怀疑这些值正在向上移动,因为当我exit(2)在孩子身上时,输出变为512.

我似乎无法在perl的waitpid中找到这个文档.这是我的系统上的错误还是我做错了什么?

Sea*_*ean 24

$?perlvar手册页的部分中有记录.

即真正的退出代码是$? >> 8.

  • 它也包含在[perldoc -f system](http://perldoc.perl.org/functions/system.html)中. (9认同)