5

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?

Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327

2 Answers2

4

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

Community
  • 1
  • 1
Anders Asplund
  • 575
  • 2
  • 7
-2

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

Community
  • 1
  • 1
Bob Swerdlow
  • 542
  • 7
  • 7