我启动一个新的 bash shell,然后执行:
ulimit -m 102400
ulimit -a
"
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) 102400
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
"
然后,我执行编译一个巨大的项目。它的链接将使用大内存,超过 2G。结果,进程ld使用了超过2G的常驻内存。
有什么不妥吗?如何使用ulimit或者我可以使用其他程序来限制驻留内存?
限制驻留内存的目标,是因为当一个进程几乎用完所有内存时,计算机会死机。
最佳答案
根据 setrlimit
的手册页:
RLIMIT_RSS
Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit only has effect in Linux 2.4.x, x < 30, and there only affects calls to madvise(2) specifying MADV_WILLNEED
您可能想通过 ulimit -v
关于linux - 为什么 ulimit 不能成功限制常驻内存,如何限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3360348/