Linux:ulimit命令

来自WHY42

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