I am debugging an issue with a compiled program written in c++ that is being called from a perl script. If I create a shell script that calls the compiled program directly:

#!/bin/tcsh myexecutable exit

And then run it, the last 2 lines written to the console are:

right before out-of-bounds array access Segmentation fault

If I instead write the following standalone perl script:

#!/tool/bin/perl use strict; my $cmd = "myexecutable"; system($cmd); my $exit_value = $? >> 8; my $signal_num = $? & 127; my $dumped_core = $? & 128; printf("exit_value = $exit_value, signal_num = $signal_num, dumped_cor +e = $dumped_core\n");

The last line printed from the executable is:

right before out-of-bounds array access

The values of the variables are as follows: exit_value = 0, signal_num = 11, dumped_core = 0 Why in this case is the "Segmentation fault" text not captured by the perl script? The behavior is the same if I replace this line:

system($cmd);
with this:
my $backtick_return = `$cmd`;

and then print $backtick_return at the end of the program. When I first started debugging this issue I was unaware of how to properly check system() return codes. Now that I've added that check as shown above debugging future issues should be easier, but I would still like to know why the "Segmentation fault" text isn't being captured by the system command, as seeing that when I first started debugging this issue would have been helpful.


In reply to "Segmentation fault" text not captured by perl script 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.