http://qs321.pair.com?node_id=11120244

Special_K has asked for the wisdom of the Perl Monks concerning the following question:

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.