I have set ulimit -m 1000000
for my shell, then started a process that consumes a bunch of memory (a simple python script from https://unix.stackexchange.com/questions/99334/how-to-fill-90-of-the-free-memory). I tell my python script to consume 2G of memory and it appears to do so (this output from htop):
Mem[|||||||||||||||||||||||||||||||||1742/1839MB] Uptime: 137 days(!), 16:56:32
Swp[||||||||||||| 591/2047MB]
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
6207 mikes 20 0 2123M 1625M 156 S 0.0 88.3 0:08.77 python ./consume_memory 2000
...Look at the "RES" column and the "MEM" graph above.
ulimit -a
shows:
max memory size (kbytes, -m) 1000000
...Why didn't my process fail to start? If I set my virtual memory size with ulimit -v 1500000
, for example, my process fails as expected:
$ ./consume_memory 900
Traceback (most recent call last):
File "./consume_memory", line 14, in <module>
data = megabyte * count
MemoryError
System specs:
CentOS Linux release 7.2.1511 (Core)
Linux hostname 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)