in reply to return value from system call, exit status, shift right 8, bitwise and, $?
and the low 8 are the signal id. Is that correct?
No, the low 7 bits indicate the signal that ended the process. Bit 7 indicates whether a core dump was saved.
What does it mean to check if it's -1?
system itself encountered an error. For example, system will return -1 and set $! if the program to execute is not found.
or would [system(...) == 0 or die "Failed!";] suffice?
It can also be written as
system(...) and die "Failed!";
It will die on any error, but not saying what failed and not saying why it failed seems insufficient to me. The user should at least be told what failed for an error that's not a programming error; a line number doesn't cut it.
Now, detecting whether a code dump occurred or not is going overboard.
This is pretty minimal:
sub _system { my $prog = shift; my $rv = system( { $prog } $prog => @_ ); if ($rv == -1) { die("Can't launch $prog: $!\n"); } elsif (my $s = $rv & 127) { die("$prog died from signal $s\n"); } elsif (my $e = $rv >> 8) { die("$prog exited with code $e\n"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: return value from system call, exit status, shift right 8, bitwise and, $?
by Anonymous Monk on Feb 11, 2010 at 15:03 UTC | |
|
Re^2: return value from system call, exit status, shift right 8, bitwise and, $?
by 7stud (Deacon) on Feb 11, 2010 at 10:18 UTC | |
by ikegami (Patriarch) on Feb 11, 2010 at 15:55 UTC |