Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Catching errors (II).

by Steve_BZ (Chaplain)
on Oct 30, 2014 at 14:08 UTC ( [id://1105630]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Guys,

This carries on from Catching errors.. I took the advice of saberworks and instituted a custom die and warn routine like this:

BEGIN{ $SIG{__DIE__} = \&customDieFatalErr; $SIG{__WARN__} = \&customWarning; }

So now I get any uncaught perl errors and warnings in my email. It is totally wonderful. Errors are reported automatically by the failing system, and can be fixed before the user even complains!

But What about the dreaded segfault?

Guys, what should I do?

I'm thinking about having a calling routine (a Perl app or bashscript) that catches the error and then reports it to me before automatically restarting the application. What do you think?

Regards,

Steve.

Replies are listed 'Best First'.
Re: Catching errors (II).
by ikegami (Patriarch) on Oct 30, 2014 at 14:50 UTC
    The parent is notified of which signal killed a child. If you wanted to monitor that, you could write a wrapper.
    use IPC::Open3 qw( open3 ); my $child_pid = open3( '<&STDIN', '>&STDOUT', *CHILD_ERROR, @ARGV ); my $error = ''; 1 while read(CHILD_ERROR, $error, 64*1024, length($error)); $error .= "\n" if length($error) && substr($error, -1) ne "\n"; waitpid($child_pid, 0); my $code = 0; if ($? & 0x7F) { $error .= "Child killed by signal ".( $? & 0x7F )."\n"; $code = 0x80 | $?; } elsif ($? >> 8) { $error .= "Child exited with error ".( $? >> 8 )."\n"; $code = $? >> 8; } if (length($error)) { # Email $error here. } exit($code);

    (As you can see, you no longer need custom handlers for warnings and exceptions in the script itself, unless you want to add stack backtraces.)

      Hi Ikegami,

      I'm trying it out now.

      Thanks very much,

      Steve.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1105630]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found