tags:

views:

86

answers:

1

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 $?;

Running the script on Solaris 10 I get this result:

$ perl test.pl
256

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

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?

+11  A: 

It's documented in the $? section of the perlvar man page.

i.e. the real exit code is $? >> 8.

Sean
It's also covered in [perldoc -f system](http://perldoc.perl.org/functions/system.html).
Ether