linux - 为什么 ulimit 不能成功限制常驻内存,如何限制?

标签 linux shell administration ulimit

我启动一个新的 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/

相关文章:

ubuntu - GConf gconftool - spawn 不起作用

c - `(void) inotify_rm_watch(fd, wd)` 和 `inotify_rm_watch(fd, wd)` 之间的区别

linux - 这是等待 10 秒获取 IP 地址的有效方法吗?

shell - Y 出现 X 次后 AWK 分割文件

java - 如何按列值分组到行和列标题中,然后动态对列求和

linux - 是否可以在守护进程不关闭文件的情况下修剪守护进程打开的日志文件?

migration - 将数据库从一台 Informix IDS 11 服务器复制到另一台服务器的最简单方法是什么

linux - 我无法通过 HTTP POST 请求将 XML 数据从特定客户端发送到特定服务器。我该如何调试?

linux - 使用 sed 删除 CIDR

linux - 在 unix 中备份特定限制的文件