English 中文(简体)
为什么要花钱? • 归还被遗忘的退出法的错误价值?
原标题:Why is Perl s $? returning the wrong value for the exit code of a forked process?
  • 时间:2010-05-25 22:34:09
  •  标签:
  • perl
  • waitpid

考虑fork(,然后等待一名儿童在Perl死亡:

#!/usr/bin/perl

use strict;
use warnings;

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

waitpid(-1,0);

print $?;

操作Solais 10号文字,我得出这一结果:

$ perl test.pl
256

我怀疑这些价值观正在向上转移,因为当我读到exit(2)时,该产出就变成了512<>。

我似乎无法在以下每一页找到这一文件:waitpid。 这是否是对我的制度的一种ug笑,或者我是否做过错?

最佳回答
问题回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...