in reply to Remaining Memory on a system

I would limit the memory available to the script, with ulimit(1), setrlimit(2), or the program softlimit from the daemontools package.

According to a quick SuperSearch and Google search, you may be able to trap the error with a $SIG{__DIE__} handler if you set the $^M variable:

Replies are listed 'Best First'.
Re: Re: Remaining Memory on a system
by smellysocks (Beadle) on Aug 29, 2003 at 16:08 UTC
    I am not concerned about the server running out of memory therfor ulimit will not help.

    What I am concerned about is getting information that my app spent over 8 hours processing and prevent reports like this:

    # more runfwrpt-20030829-0230
    Out of memory during request for 24 bytes, total sbrk() is 317718640 bytes!
    Out of memory during request for 1016 bytes, total sbrk() is 317718640 bytes!
    Out of memory during request for 1016 bytes, total sbrk() is 317718640 bytes!


    The above isn't a very usefull report...

    Even if it only processed half of the files I'd rather have it spit out an error message, and report what it has processed so far.
      See the entry for $^M in perlvar(1):
      By default, running out of memory is an untrappable, fatal error. However, if suitably built, Perl can use the contents of "$^M" as an emergency memory pool after die()ing. Suppose that your Perl were compiled with -DPERL_EMERGENCY_SBRK and used Perl's malloc. Then $^M = 'a' x (1 << 16); would allocate a 64K buffer for use in an emergency. See the INSTALL file in the Perl distribution for information on how to enable this option. To discourage casual use of this advanced feature, there is no English long name for this variable.