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.