For reference, this is somewhat of a follow up question to a question I asked previously: https://perlmonks.org/?node_id=11120004

What is the impact on the value of $? if the output of an application is redirected to /dev/null? This is running under RHEL7.

For example, suppose I have a perl script that calls a compiled executable that seg faults:

`my_executable_that_seg_faults`; my $exit_value = $? >> 8; my $signal_num = $? & 127; my $dumped_core = $? & 128; printf("return value is %d\n", $?); printf("exit_value = $exit_value\n"); printf("signal_num = $signal_num\n"); printf("dumped_core = $dumped_core\n");

Running the above code produces the following output:

return value is 11 exit_value = 0 signal_num = 11 dumped_core = 0

This output is consistent with what I would expect based on information found here related to the $? variable: https://perldoc.perl.org/perlvar.html

However if I change the executable call above to the following:

`my_executable_that_seg_faults > /dev/null`;

The following output is produced:

return value is 35584 exit_value = 139 signal_num = 0 dumped_core = 0

The above output is significantly different even though the application still seg faulted. Here are my questions:

1. Why did the value of $? completely change when I added the output redirect to /dev/null but kept everything else the same?

2. Does the value of $? in the second case still contain the same information but encoded differently?

I created a different application with an intentional segmentation fault and called it using the above perl script. It produced the exact same output, suggesting that this behavior is not dependent on the behavior of the called application.


In reply to Effect of redirecting output to /dev/null on $? value by Special_K

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.