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

Sam Watkins sam at nipl.net
Thu Oct 2 19:19:06 PDT 2014


What operating system are you running the scripts on?  Linux, at least,
does not handle out-of-memory conditions very well.  It over-allocates
memory, and if memory runs out the kernel kills likely processes.  You
won't see an "out of memory" error from malloc (or whatever) under
linux.  Also, when the system is low on memory things tend to grind to a
halt with excessive swapping.  You might want to catch the problem
before it gets to this stage.

Also, if a program "dies" with an error, the END {} block is not called.
You would need a $SIG{__DIE__} handler or eval {} block to catch the
error.  I'm not sure if perl needs memory to continue basic processing
such as entering a function.

I suggest to find or write a program that can monitor your processes
from the outside, and alert you if a process is using too much memory,
or if a process dies unexpectedly.


On Fri, Oct 03, 2014 at 11:54:12AM +1000, Bradley Dean 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


More information about the Melbourne-pm mailing list