命令名称:
ulimit - 限制当前shell及其子进程的可用资源多少。
ulimit命令语法:
ulimit [OPTION]... number
number是数字,也可以是"unlimited“,代表”无穷大,不限制“。
ulimit命令讲解:
ulimit并不是针对用户做限制,而是针对当前shell。如果同一个用户同时登陆运行了两个shell,那么在其中一个shell中的ulimit限制不会影响另一个shell。如果想限制指定用户,请看这里:限制指定用户资源
我们可以通过将ulimit命令写在/etc/rc.local中,从而实现开机自动设置。另外,默认情况下,linux普通用户不能使用ulimit命令。
ulimit命令是bash的内置命令,man ulimit会直接跳转到man builtins的页面,可以翻页到比较后的位置查看ulimit项目,或者shell下直接help ulimit。
ulimit命令常用选项:
-H 使用硬资源控制 -S 使用软资源控制 -a 查看所有的当前限制 -n 能打开的最大文件描述符数 -t 限制最大的 CPU 占用时间(每秒) -u 限制最大用户进程数 -v 限制虚拟内存大小(kB)
ulimit命令其他选项:
-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 a process may lock into memory -m the maximum resident set size (has no effect on Linux) -n the maximum number of open file descriptors -p the pipe buffer size -q the maximum number of bytes in POSIX message queues -r the maximum real-time scheduling priority -s the maximum stack size -x the maximum number of file locks
ulimit命令实例:
ulimit -HSn 65536 #硬资源和软资源同时限制为最大打开文件描述符数65546 ulimit -v ulimited #将虚拟内存限制改为无限制