My programs exhaust memory like half of times I run them. Under Linux I'm able to set a tough limit towards the available memory using ulimit -v mem-in-kbytes. Really, I personally use ulimit -S -v mem-in-kbytes, and so i obtain a proper memory allocation issue in the program and that i can abort.

But... ulimit isn't employed in OSX 10.6. I have attempted with -s and -m options, and they're no longer working.

In 2008 there is some discussion comparable problem in MacRumors, but nobody suggested a great alternative. The ought to be a means a course can learn it's investing an excessive amount of memory, or setting a restriction with the OS.

Use launchctl limit:

[~]> sudo launchctl limit

cpu         limitless      limitless

filesize    limitless      limitless

data        limitless      limitless

stack       8388608        67104768

core                      limitless

rss         limitless      limitless

memlock     limitless      limitless

maxproc     266            532

maxfiles    256            limitless

[~]> sudo launchctl limit rss 100000

[~]> sudo launchctl limit

cpu         limitless      limitless

filesize    limitless      limitless

data        limitless      limitless

stack       8388608        67104768

core                      limitless

rss         100000         100000

memlock     limitless      limitless

maxproc     266            532

maxfiles    256            limitless

After battling with this particular myself (with limited success), I've determined there appears to become two ways to get it done...

You are able to setup a launchd item for the executable.. The key area of the plist is really a section, for example..

<key>SoftResourceLimits</key>

<dict>

    <key>Stack</key>

    <integer>10000000000</integer>

</dict>

You will find various secrets available... that exist on Apple's Guy page.

A different way to get it done, I believe, is as simple as setting something either in /etc/launchd.conf (system) or /etc/launchd-usr.conf (peruser). For instance, your launchd.conf could contain...

umask 002

limit stack 67104768 67104768

limit maxproc 3400 4500

limit maxfiles 256 limitless

setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

The documentation its launchd's functionality is shotty, should you request me.. It's as though Apple may not care / want people outdoors their walls to really experience how it all works. There's a lot energy available by learning launchd and it is particulars... but you will find couple of concrete/official assets available regarding how you can correctly implement them.

setrlimit should get the job done. In my opinion this is the BSD same as ulimit...