简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM