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"); } }

In reply to Re: return value from system call, exit status, shift right 8, bitwise and, $? by ikegami
in thread return value from system call, exit status, shift right 8, bitwise and, $? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.