Below is the C code that is meant to fail:
#include<stdio.h> #include<stdlib.h> int main() { char *p = NULL; printf("Value at P: %c\n", *p); return 0; }
When I compile and run it (RH4 machine with gcc 4.5.2), it predictably gives a segmentation error:
% ./a.out Segmentation fault % echo $status 139
If I run it with Perl v5.8.5, this will happen:
% perl -e 'system("./a.out") and die "Status: $?"' Status: 11 at -e line 1.
Perlvar documentation for $? says that
So the output value of the subprocess is really ($?>> 8 ) , and $? & 127 $? & 127 indicates which signal, if any, has passed away, and $? & 128 $? & 128 reports whether there was a core dump.
11 >> 8 0 , and 11 & 127 - 11 .
Why different exit statuses? If we cannot depend on the exit status, what should be the way to detect a segmentation error in an external command?
perl
Unos
source share