每当我的某个用户运行“R”脚本(此脚本需要大量内存)时,我的服务器就会崩溃。以下是top我最后看到的:
top - 11:32:39 up 20 min, 4 users, load average: 1.08, 0.85, 0.46
Tasks: 336 total, 2 running, 334 sleeping, 0 stopped, 0 zombie
Cpu(s): 6.1%us, 0.2%sy, 0.0%ni, 93.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 65939968k total, 5131440k used, 60808528k free, 88256k buffers
Swap: 68124664k total, 0k used, 68124664k free, 1077612k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10392 cdina 25 0 3702m 3.5g 2428 R 100.0 5.6 7:51.82 R
10430 root 15 0 12872 1272 804 R 0.7 0.0 0:02.42 top
1 root 15 0 10348 704 592 S 0.0 0.0 0:02.95 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
有没有办法防止我的服务器崩溃(“不要运行该脚本”不是一个选项:-))?比如修复允许的内存的“配额”?
(更新)建筑学:
uname -a
Linux myserver 2.6.18-194.3.1.el5 #1 SMP Sun May 2 04:17:42 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
#R was compiled on the server. just a simple configure/make/install
R --version
R version 2.11.0 (2010-04-22)
file /usr/local/lib64/R/bin/exec/R
R: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
答案1
如何使用 /etc/security/limits.conf 来限制用户的 CPU 数量。
或者:
ulimit -m <大小(以兆字节为单位)>
在 shell 中,然后执行该过程。