Jakub Arnold
Jakub Arnold

Reputation: 87230

How can I run a process with a hard memory limit on OS X?

I'm implementing an algorithm that needs to run under a hard memory limit of 4MB.

Is there a way to run a process in a way that it would get killed if it over-reaches its memory limit? Or simply just profile its allocations to be able to see how much maximum memory has been allocated?

Upvotes: 5

Views: 2698

Answers (2)

Anders Asplund
Anders Asplund

Reputation: 575

I think ulimit is what you're looking for: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/ulimit.3.html

Ulimit don't work all the time though, and alternative ways of limiting a process system resources is mentioned here: How to limit memory of a OS X program? ulimit -v neither -m are working

Also the same question has been asked here, so this question might bring some enlightenment on the problem, especially concerning virtual memory: https://apple.stackexchange.com/questions/43371/way-to-limit-how-much-ram-an-arbitrary-process-can-take-up

You will probably get a hard limit by following this tip thou, together with the use of ulimit: http://hints.macworld.com/article.php?story=201106020948369

Upvotes: 4

Bob Swerdlow
Bob Swerdlow

Reputation: 542

Look at this to install coretools with brew: Timeout Command on Mac OS X? then use gtimeout -m 4096 myscript

Upvotes: -2

Related Questions