I am trying to limit the memory usage of a process
$ulimit -m 2 $/usr/bin/time -l ./myProcess arg1 arg2
The process run without being killed until
7.00 real 4.83 user 2.16 sys 4154855424 maximum resident set size 0 average shared memory size 0 average unshared data size 0 average unshared stack size 1014384 page reclaims 0 page faults 0 swaps 0 block input operations 2 block output operations 0 messages sent 0 messages received 0 signals received 0 voluntary context switches 15 involuntary context switches
showing that the limit has been overpassed despite the
ulimit -m 5 command line. I have also tried the options
-l but none of them seem to actually limit the memory usage. I also tried with
time to make sure it would not fail to see the memory usage of a subprocess. Here are all limits after using all
$ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited file size (blocks, -f) unlimited max locked memory (kbytes, -l) 3 max memory size (kbytes, -m) 2 open files (-n) 256 pipe size (512 bytes, -p) 1 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 709 virtual memory (kbytes, -v) 2
If I limit the CPU time (
ulimit -t 3), then it works fine and kill the process after 3 seconds.
Is there something I misunderstand about
ulimit -m 5? Is there a bug in my ulimit version?
Is there an alternative to
ulimit to limit time and memory usage of a process (not necessarily the bash session)?
I am on
MAC OSX 10.11.6 and
bash version 3.2.57.
The post "ulimit not limiting memory usage" is very related but I don't think the accepted answer offer any solution on how to solve the problem