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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.