Linux:ulimit命令:修订间差异

来自WHY42
imported>Soleverlee
以“ulimit is a builtin shell command used to show and set various restrictions on resource usage for a shell. Among the limitations that can be set you find, maximum fi...”为内容创建页面
 
imported>Soleverlee
无编辑摘要
第7行: 第7行:
[[Image:Ulimit_Sample.png|600px]]
[[Image:Ulimit_Sample.png|600px]]


In general, the command ulimit -$ (where $ is some letter) will return the current value of the variable linked with $, while ulimit -$ NUMBER (again, where $ is some letter, and NUMBER is generally an integer, or "unlimited") will set that variable. Of special note is the -a option, which will display all limits for the system.
The -H and -S options are also special. -H will affect the "hard" limit, which is an absolute limit on a resource. -S will affect the "soft" limit. The major difference between the two is that hard limits can only be increased by root. Since the default for options is to affect both hard and soft limits, adding -S to a command will allow returning the variable to the previous value without root access.
Finally, all limits only apply to the thread in which they are set. For systemwide setting of limits, try /etc/security/limits.conf
[[Category:Linux/Unix]]
[[Category:Linux/Unix]]

2016年8月19日 (五) 01:53的版本

ulimit is a builtin shell command used to show and set various restrictions on resource usage for a shell. Among the limitations that can be set you find, maximum file size, maximum core file size, maximum size of resident memory. Though the restrictions are shell-independent, the exact syntax depends on what shell you are running.

It is a good practice to set some of these limitations to prevent for instance a faulty shell script to start unlimited copies of itself or to prevent users on the system to start processes that run forever.

Warning: Typing ulimit may result in the output "unlimited". That is misleading, you may have limits in place as you can find out with ulimit -a

In general, the command ulimit -$ (where $ is some letter) will return the current value of the variable linked with $, while ulimit -$ NUMBER (again, where $ is some letter, and NUMBER is generally an integer, or "unlimited") will set that variable. Of special note is the -a option, which will display all limits for the system. The -H and -S options are also special. -H will affect the "hard" limit, which is an absolute limit on a resource. -S will affect the "soft" limit. The major difference between the two is that hard limits can only be increased by root. Since the default for options is to affect both hard and soft limits, adding -S to a command will allow returning the variable to the previous value without root access. Finally, all limits only apply to the thread in which they are set. For systemwide setting of limits, try /etc/security/limits.conf