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

I am executing a script say x.pl from y.pl using system command.I capture the status of system command.Sometimes x.pl successfully executes its last statement, but when i capture the error in y.pl , it gives me error status segmentation fault.

Replies are listed 'Best First'.
Re: segmentation fault for perl
by ikegami (Patriarch) on Jul 03, 2009 at 15:52 UTC

    The value returned by system/$? is from the OS. If the OS says the child segfaulted, there's not much Perl can do but to trust it.

    I find it very unlikely that the OS would say it segfaulted if it didn't.

    Update: Not on Windows, I suppose. Windows has larger exit codes that are squished into the unix format. Are you on Windows? Maybe there's a bug in the emulation.

      My os is solaris 10. Stating the problem again. I am invoking the script x.pl from y.pl as system(x.pl); my $exit_status = $? >> 8; I am capturing the status always. It sometimes happen that x.pl is able to execute successfuly (it updates a database before exiting). But capturing the error status in y.pl shows the system(x.pl) has a exit status of segmentation fault.

        You can't find out if a segfault occured by looking at $? >> 8. Do you mean $? & 127? What's the value of $??

        In any case, if a segfault did occur, I can't see how Perl was responsible.

Re: segmentation fault for perl
by rovf (Priest) on Jul 03, 2009 at 15:47 UTC

    How do you call y.pl when you capture the error, as opposed to when not capturing the error?

    -- 
    Ronald Fischer <ynnor@mm.st>
      I am invoking the script x.pl from y.pl as system(x.pl); my $exit_status = $? >> 8; I am capturing the status always. It sometimes happen that x.pl is able to execute successfuly (it updates a database before exiting). But capturing the error status in y.pl shows the system(x.pl) has a exit status of segmentation fault. My os is solaris 10
        I am invoking the script x.pl from y.pl as system(x.pl);

        I take it to mean system('x.pl');. And I guess you made sure that x.pl has a correct #! line?

        my $exit_status = $? >> 8; I am capturing the status always.
        How do you know that your program died by segmentation fault? $? >> 8 is whatever x.pl passes to its exit call, so from this value alone, you can not deduce that your program segfaulted.

        But *if* it does, it could be that either the Perl used has a problem (that's why I'm asking you about the #! line), or (more likely) that x.pl uses some Perl module which contains compiled parts, so this would be the place to look.

        -- 
        Ronald Fischer <ynnor@mm.st>