Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Help checking program return values

by hippo (Bishop)
on Jul 29, 2020 at 18:03 UTC ( [id://11120006]=note: print w/replies, xml ) Need Help??


in reply to Help checking program return values

You haven't said which O/S you are running on and that might well have an impact here.

elseif ($signal_num != 0)

That isn't Perl, so either the code you are showing isn't the code you are running or your code isn't running at all.

The upper 8 bits had an exit code of 139, which indicates a seg fault, but the signal for seg fault was not set.

An exit code of 139 does not necessarily indicate a seg fault. Trivially:

#!/usr/bin/env perl use strict; use warnings; system ('perl -e "exit 139"'); my $exit_value = $? >> 8; my $signal_num = $? & 127; my $dumped_core = $? & 128; print <<EOT Exit value: $exit_value Signal: $signal_num Core: $dumped_core EOT
Is there a module or library I can use to automatically catch all of the "bad" return values so I don't have to code all of the enumerations of signals and return values myself?

Unlikely because your idea of "bad" may not be someone else's idea of "bad". However, you could simply write your own module for your own use and then use that in all your other code.


🦛

Replies are listed 'Best First'.
Re^2: Help checking program return values
by Special_K (Monk) on Jul 29, 2020 at 18:44 UTC
    > You haven't said which O/S you are running on and that might well have an impact here.

    Linux (I've updated my post to say this).

    > That isn't Perl, so either the code you are showing isn't the code you are running or your code isn't running at all.

    Correct, it should have said "elsif" as I manually typed that out into the web submission form. This has also been corrected.

    > An exit code of 139 does not necessarily indicate a seg fault. Trivially:

    Correct, I could make an executable return any code I want it to under any circumstances, but assuming I'm only using the return codes 0 and 255 inside the executable to indicate correct and incorrect return values respectively, what is the most reliable way to detect a segmentation fault (or other undesirable return values) that were initiated by the OS?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-19 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found