ulimit参数详解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ulimit -a
core file size          (blocks, -c)  0     //限制内核文件的大小限制
data seg size           (kbytes, -d) unlimited   //最大数据大小限制
scheduling priority             (-e)  0    //调度优先级,一般根据nice设置
file size               (blocks, -f) unlimited   //最大文件大小限制
pending signals                 (-i)  192088   //信号可以被挂起的最大数,这个值针对所有用户,表示可以被挂起/阻塞的最大信号数量。
max locked memory       (kbytes, -l)  8000   //内存锁定值的限制
max memory size         (kbytes, -m) unlimited  //最大可以使用内存限制
open files                      (-n)  409600  //进程打开文件数的限制
pipe size            ( 512  bytes, -p)  8    //管道文件大小限制
POSIX message queues     (bytes, -q)  819200   //可以创建使用POSIX消息队列的最大值,单位为bytes
real-time priority              (-r)  0    //限制程序实时优先级的范围,只针对普通用户
stack size              (kbytes, -s)  10240    //限制进程使用堆栈段的大小
cpu time               (seconds, -t) unlimited   //)程序占用CPU的时间,单位是秒
max user processes              (-u)  409600   //限制程序可以fork的进程数,只对普通用户有效
virtual memory          (kbytes, -v) unlimited   //限制进程使用虚拟内存的大小
file locks                      (-x) unlimited   //锁定文件大小限制

用法说明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-a     All current limits are reported
-b     The maximum socket buffer size
-c     The maximum size of core files created
-d     The maximum size of a process's data segment
-e     The maximum scheduling priority ( "nice" )
-f     The maximum size of files written by the shell and its children
-i     The maximum number of pending signals
-l     The maximum size that may be locked into memory
-m     The maximum resident  set  size (many systems  do  not honor  this  limit)
-n     The maximum number of open file descriptors (most systems  do  not allow  this  value to be  set )
-p     The pipe size  in  512 -byte blocks ( this  may not be  set )
-q     The maximum number of bytes  in  POSIX message queues
-r     The maximum real-time scheduling priority
-s     The maximum stack size
-t     The maximum amount of cpu time  in  seconds
-u     The maximum number of processes available to a single user
-v     The maximum amount of virtual memory available to the shell
-x     The maximum number of file locks
-T     The maximum number of threads

/etc/security/limits.conf 文件说明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<domain>        <type>  <item>  <value>
 
<domain>:
        ckl  //用户
        @student  //组
        //通配符,所有用户
        //通配符,用在组的语法
       
<type>:
       soft  //软限制
       hard  //硬限制
       
<item>:
       core  //限制内核文件的大小
       data  //最大数据大小限制
       fsize  //最大文件大小限制
       memlock  //最大锁内存地址空间
       nofile  //进程打开文件数的限制
       rss  //最大持久驻留内存
       stack  //最大堆栈大小
       cpu  //最大CPU运行时间
       nproc  //最大进程数
       as  //地址空间限制
       maxlogins  //最大登录次数,用户
       maxsyslogins  //最大登录次数,登录此系统的最大次数
       priority  //用户运行的优先级
       locks  //用户锁定文件数限制
       sigpending  //信号可以被挂起的最大数
       msgqueue  //可以创建使用POSIX消息队列的最大值
       nice  //可以设置的优先级,nice [-20, 19]
       rtprio  //实时优先级,    数字大的优先级高

配置设置:

1.验证所有用户

设置进程数打开文件限制,目前是

1
2
ulimit  -n
1024
1
2
3
vim /etc/security/limits.conf 
*                soft    nofile        51200
*                hard    nofile        65535


查看:

1
2
ulimit -n
51200


2.添加用户测试core文件限制

目前是root用户

1
2
# ulimit -c
0
1
2
3
4
adduser ckl
vim /etc/security/limits.conf 
@ckl           soft    core          12000
@ckl           hard    core          12000

切换到ckl验证:

1
2
3
# su ckl
$ ulimit -c
12000
1
2
3
4
5
cat /etc/security/limits.conf
*                soft    nofile        51200
*                hard    nofile        65535
@ckl             soft    nproc         1200
@ckl             hard    nproc         1200