ulimit 用于限制 shell 启动进程所占用的资源,支持以下各种类型的限制:所创建的内核文件的大小、进程数据块的大小、Shell 进程创建文件的大小、内存锁住的大小、常驻内存集的大小、打开文件描述符的数量、分配堆栈的最大大小、CPU 时间、单个用户的最大线程数、Shell 进程所能使用的最大虚拟内存。同时,它支持硬资源和软资源的限制。
Linux文件描述符可参见笔者之前的文章:http://kumu1988.blog.51cto.com/4075018/1086210
关于RHEL6中ulimit的nproc限制,RHEL6和RHEL5还是有一些细节上的区别的:
当前shell下更改用户可打开进程数
作为临时限制,ulimit可以作用于通过使用其命令登录的 shell 会话,在会话终止时便结束限制,并不影响于其他 shell 会话。
修改limits.conf配置文件生效
[root@kumu ~]# ulimit -a //查看当前配置文件ulimit全局系数
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1829
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
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) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@kumu ~]# vim /etc/security/limits.conf
[root@kumu ~]# grep '^*' /etc/security/limits.conf
* soft nproc 10240
* hard nproc 10240
* soft nofile 10240
* hard nofile 10240
[root@kumu ~]#
[root@kumu ~]# ulimit -n
10240
[root@kumu ~]# ulimit -u //发现nproc并没有像nofile一样而改变
1024
[root@kumu ~]#
(参见了@杨德华Devin 文章redhat5 和redhat6 root用户不同的ulimits)
[root@kumu ~]# cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
[root@kumu ~]#
[root@kumu ~]# vim /etc/security/limits.d/90-nproc.conf
[root@kumu ~]# cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
#* soft nproc 1024
* soft nproc 65535
[root@kumu ~]#
[root@kumu ~]# ulimit -u
10240
[root@kumu ~]# ulimit -n
10240
[root@kumu ~]#
由此可知,如果要修改配置文件limits.conf中的nproc限制上限是受文件/etc/security/limits.d/90-nproc.conf中nproc值大小制约的,但是shell终端下是不受制约的
[root@kumu ~]# vim /etc/security/limits.d/90-nproc.conf //恢复系统默认设置
[root@kumu ~]# cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
#* soft nproc 65535
[root@kumu ~]# vim /etc/security/limits.conf //只针对某个用户测试(这里使用root)
[root@kumu ~]# grep '^root' /etc/security/limits.conf
root soft nproc 10240
root hard nproc 10240
[root@kumu ~]#
[root@kumu ~]# ulimit -u
10240
[root@kumu ~]# ulimit -n
10240
[root@kumu ~]#