<div dir="ltr">The Perl script should exit with a non-zero exit code... it doesn't really matter why that exit code was non-zero, as any non-zero value will indicate a failure mode.<div><br></div><div>eg: grep returns non-zero when it didn't actually grep for anything.... (you asked it to do something, but it couldn't).</div><div><br></div><div>Tracing STDERR will be fraught with problems - how do you know some Perl library doesn't randomly spit out messages that you have yet to see?</div><div><br></div><div><br></div><div>just my $0.02,</div><div><br></div><div>Mathew</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 October 2014 10:46, Bradley Dean <span dir="ltr"><<a href="mailto:bjdean@bjdean.id.au" target="_blank">bjdean@bjdean.id.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes - that's certainly a safer approach. In fact I've found that what<br>
worked for me in my example code was version sensitive.<br>
<br>
On the system I started with the last system call was an mmap2 with a<br>
ENOMEM error and this is what I found when checking $!. I then tested<br>
this on a different system and discovered that after the mmap2 failed<br>
(and before my perl code had a chance to look at $!) a bunch of<br>
rt_sigaction systems calls happened and one of those failed with EINVAL<br>
so there was no ENOMEM to find.<br>
<br>
I feel there's a hack with a wrapper script which greps for "Out of<br>
memory!" on STDERR coming my way as the exit code doesn't tell me<br>
anything useful either.<br>
<br>
Cheerio,<br>
<br>
 Brad<br>
<div class="HOEnZb"><div class="h5"><br>
On Fri, Oct 10, 2014, at 10:37, Toby Wintermute wrote:<br>
> I really don't think this approach is going to pay dividends.<br>
> When you're hitting out of memory conditions in Perl, it's usually<br>
> game over. In some languages you could code up something that runs<br>
> without using any more memory, as a handler, but you don't have that<br>
> level of control in Perl.<br>
><br>
> I'd look at wrapping your Perl script in another program - maybe just<br>
> a bash or even another Perl script - that waits for it to exit, and<br>
> then checks to see if it exited normally or with an error code.<br>
><br>
> On 3 October 2014 11:54, Bradley Dean <<a href="mailto:bjdean@bjdean.id.au">bjdean@bjdean.id.au</a>> wrote:<br>
> > Greetings folks,<br>
> ><br>
> > While looking at a problem where a variety of scripts might develop a<br>
> > memory leak and fatally terminate with "Out of memory!" I'm trying to<br>
> > work out if this seemingly simple code is in fact too simple:<br>
> ><br>
> > package NotifyOnOutOfMemory;<br>
> > use Errno;<br>
> > END {<br>
> >     # If the last errno indicates out of memory perl will now be<br>
> >     # terminating with "Out of memory!" so tell me about it.<br>
> >     if ( $! == Errno::ENOMEM ) {<br>
> >         # Do some low-memory thing that tells me a process has died due<br>
> >         to memory exhaustion<br>
> >         # eg. touch /path/to/some/file<br>
> >         #    or - exec("/path/to/script/which/emails/or/logs $$ $0<br>
> >         $someOtherDetail")<br>
> >      }<br>
> > }<br>
> > 1;<br>
> ><br>
> > Which would give me a drop in module for scripts with this problem.<br>
> ><br>
> > What am I missing? :)<br>
> ><br>
> > Cheerio,<br>
> ><br>
> >  Brad<br>
> ><br>
> > --<br>
> > Bradley Dean<br>
> > Email: <a href="mailto:bjdean@bjdean.id.au">bjdean@bjdean.id.au</a> Skype: <a href="mailto:skype@bjdean.id.au">skype@bjdean.id.au</a><br>
> > Mobile(Aus): <a href="tel:%2B61-413014395" value="+61413014395">+61-413014395</a> WWW: <a href="http://bjdean.id.au/" target="_blank">http://bjdean.id.au/</a><br>
> > _______________________________________________<br>
> > Melbourne-pm mailing list<br>
> > <a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
> > <a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
><br>
><br>
><br>
> --<br>
> Turning and turning in the widening gyre<br>
> The falcon cannot hear the falconer<br>
> Things fall apart; the center cannot hold<br>
> Mere anarchy is loosed upon the world<br>
<br>
<br>
--<br>
Bradley Dean<br>
Email: <a href="mailto:bjdean@bjdean.id.au">bjdean@bjdean.id.au</a> Skype: <a href="mailto:skype@bjdean.id.au">skype@bjdean.id.au</a><br>
Mobile(Aus): <a href="tel:%2B61-413014395" value="+61413014395">+61-413014395</a> WWW: <a href="http://bjdean.id.au/" target="_blank">http://bjdean.id.au/</a><br>
_______________________________________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
</div></div></blockquote></div><br></div>