Ulimit: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:
The -H and -S options specify that the hard or soft limit is set for the given resource.  
The -H and -S options specify that the hard or soft limit is set for the given resource.  


<span id="hard_limit"></span>A ''hard limit'' cannot be increased by a non-root user once it is set.
<span id="hard_limit"></span>The ''hard limit'' is the upper bound of the property, set by root. A hard  limi' cannot be increased by a non-root user once it is set.


<span id="soft_limit"></span>A soft limit may be increased by the non-root user up to the value of the hard limit.  
<span id="soft_limit"></span>The ''soft limit'' is the per-user limit that can be adjusted at run time (using ulimit) up to the hard limit. A soft limit may be increased by the non-root user up to the value of the hard limit.  


The hard limit is the upper bound of the property, set by root.  The soft limit is the per-user limit that can be adjusted at run time (using ulimit) up to the hard limit.
These limits can be set up for the current shell with <tt>ulimit</tt> or permanently in /etc/security/limits.conf specifically for the account we want, as shown below:
 
These limits can be set up permanently in /etc/security/limits.conf specifically for the account we want:


<pre>
<pre>

Revision as of 20:20, 21 April 2017

Internal

Overview

Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.

Hard and Soft Limits

The -H and -S options specify that the hard or soft limit is set for the given resource.

The hard limit is the upper bound of the property, set by root. A hard limi' cannot be increased by a non-root user once it is set.

The soft limit is the per-user limit that can be adjusted at run time (using ulimit) up to the hard limit. A soft limit may be increased by the non-root user up to the value of the hard limit.

These limits can be set up for the current shell with ulimit or permanently in /etc/security/limits.conf specifically for the account we want, as shown below:

jbossusr soft nofile 16384
jbossusr hard nofile 16384

Options

  • -a All current limits are reported
[root@rhel-test ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3901
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3901
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
  • -b The maximum socket buffer size
  • -c The maximum size of core files created
  • -d The maximum size of a process' 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

To Get the Soft Limit of a Value

If limit is omitted, the current value of the soft limit of the resource is printed, unless the -H option is given. When more than one resource is specified, the limit name and unit are printed before the value.

ulimit -n

To Get the Hard Limit for a Value

ulimit -Hn

To Set A Value

Use ulimit or declare the values in /etc/security/limits.conf, as described below.

When using ulimit, if neither -H nor -S is specified, both the soft and hard limits are set. The value of limit can be a number in the unit specified for the resource or one of the special values "hard", "soft", or "unlimited", which stand for the current hard limit, the current soft limit, and no limit, respectively.

Current Shell

To change the limit in the current shell, use:

ulimit -n <new-hard-and-soft-limit>

The limit set this way does propagate to sub-shells, but it is not persisted, so if you need your change to survive the current shell, you may want to change it in [[]] or [[]]:

.bashrc

Edit the corresponding .bashrc and add the following (for example, for file descriptors) but make sure it's under the hard limit set by root:

ulimit -n 2048

/etc/security/limits.conf

jbossusr soft nofile 16384
jbossusr hard nofile 16384

This change does not require a reboot - only that all processes belonging to the user are killed and restarted, so they can use the new value.

Note that configuration files in /etc/security/limits.d directory, which are read in alphabetical order, override the settings in this file in case the domain is the same or more specific.

A good practice would be to modify those files first.

For example, the file that controls noproc and overrides /etc/security/limits.conf is /etc/security/limits.d/90-nproc.conf:


*          soft    nproc     1024
root       soft    nproc     unlimited