ulimit命令用于限制liunx的每个用户的资源限制,包括文件句柄,一时间打开的文件数,进程数,内存大小等
常用的参数命令
ulimit -a #显示目前的资源设定/临时设置设置core上限值
ulimit -n #查看目前设定的文件句柄,单位为KB
ulimit -c #查看目前设置的core文件的最大值,单位为区快
ulimit -p #查看管道缓冲区的大小,单位512字节;
ulimit -u #查看用户最多可开启的程序数目;
ulimit -m #查看指定可使用内存的上限,单位为KB;
...
上述这些命令在除a参数,其他在后面加上限制的大小即可临时限制资源大小,例如:
ulimit -n 65535
临时设置文件句柄限制为65535
永久修改限制
修改/etc/secyrity/limits.conf文件
所有相关limit命令的相关设置也可在该文件看到
vim /etc/security/limits.conf
下面是我的该文件配置,设置了文件句柄为65535还有内存设置了16G
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# - a user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
* soft nofile 65535
* hard nofile 65535
* soft rss 16777215
* hard rss 16777215
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open file descriptors
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
#<domain> <type> <item> <value>
#
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
# End of file