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