为什么是Perl的$?为派生进程的退出代码返回错误的值? [英] Why is Perl's $? returning the wrong value for the exit code of a forked process?

查看:113
本文介绍了为什么是Perl的$?为派生进程的退出代码返回错误的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下简单例子,其中 fork()然后等待孩子死掉在Perl中:

Consider this trivial example of fork()ing then waiting for a child to die in Perl:

#!/usr/bin/perl

use strict;
use warnings;

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

waitpid(-1,0);

print $?;

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

Running the script on Solaris 10 I get this result:

$ perl test.pl
256

我怀疑的值正在向上移动,因为当我在孩子中执行exit(2)时,输出将变为512.

I suspect the values of are being shifted upwards because when I do exit(2) in the child, the output becomes 512.

我似乎找不到在perl的 waitpid 中记录的内容.这是我系统上的错误还是我做错了什么?

I can't seem to find this documented in perl's waitpid. Is this a bug on my system or am I doing something wrong?

推荐答案

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

这篇关于为什么是Perl的$?为派生进程的退出代码返回错误的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆