[Israel.pm] catching segmentation faults and other crashes

Mikhael Goikhman migo at homemail.com
Mon Nov 12 03:13:18 PST 2007


On 12 Nov 2007 12:54:56 +0200, Yona Shlomo wrote:
> 
> On Mon, 12 Nov 2007, Mikhael Goikhman wrote:
> 
> > On 12 Nov 2007 09:51:04 +0200, Yona Shlomo wrote:
> >>
> >> Can you recommend a way to catch the crash of the tool, despite the
> >> fact that it still emits some (possibly good) output?
> >
> > Run these commands, one with and one without internal segfault:
> >
> >  perl -e 'print qx(perl -e "\$| = 1; print qq(output\n); 1 && dump()"); print "Core dumped\n" if $? & 128'
> >
> >  perl -e 'print qx(perl -e "\$| = 1; print qq(output\n); 0 && dump()"); print "Core dumped\n" if $? & 128'
> >
> > You should remember to remove core files if any (named like core or
> > perl.core or core.12345, depending on the OS).
> 
> I must admit that I don't understand what you're trying to do.

I just do what you asked above, i.e. "recommend a way to catch the crash
of the tool (executed using qx()), despite the fact that it still emits
some (possibly good) output".  Did you run these commands from a shell?

Accouding to "perldoc -f system", positive $? after system() or qx()
includes the system signal which the invoked command died with (something
you probably are not interested in) plus 128 on segmentation fault
(something you are interested in).

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list