[Melbourne-pm] Finding "Out of memory!"

Toby Wintermute tjc at wintrmute.net
Thu Oct 9 16:37:49 PDT 2014

I really don't think this approach is going to pay dividends.
When you're hitting out of memory conditions in Perl, it's usually
game over. In some languages you could code up something that runs
without using any more memory, as a handler, but you don't have that
level of control in Perl.

I'd look at wrapping your Perl script in another program - maybe just
a bash or even another Perl script - that waits for it to exit, and
then checks to see if it exited normally or with an error code.

On 3 October 2014 11:54, Bradley Dean <bjdean at bjdean.id.au> wrote:
> Greetings folks,
> While looking at a problem where a variety of scripts might develop a
> memory leak and fatally terminate with "Out of memory!" I'm trying to
> work out if this seemingly simple code is in fact too simple:
> package NotifyOnOutOfMemory;
> use Errno;
> END {
>     # If the last errno indicates out of memory perl will now be
>     # terminating with "Out of memory!" so tell me about it.
>     if ( $! == Errno::ENOMEM ) {
>         # Do some low-memory thing that tells me a process has died due
>         to memory exhaustion
>         # eg. touch /path/to/some/file
>         #    or - exec("/path/to/script/which/emails/or/logs $$ $0
>         $someOtherDetail")
>      }
> }
> 1;
> Which would give me a drop in module for scripts with this problem.
> What am I missing? :)
> Cheerio,
>  Brad
> --
> Bradley Dean
> Email: bjdean at bjdean.id.au Skype: skype at bjdean.id.au
> Mobile(Aus): +61-413014395 WWW: http://bjdean.id.au/
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm

Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

More information about the Melbourne-pm mailing list