Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 538
Jakub Arnold Avatar asked Oct 31 '22 09:10

Jakub Arnold


1 Answers

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

like image 64
Anders Asplund Avatar answered Nov 09 '22 10:11

Anders Asplund