Ulimit - User Resource Control

On systems that support it, provides control over the resources available to a shell and the processes it starts. The -H and -S options specify hard and soft limits set for a given resource. A soft limit further restricts, within what the current system can bear, how many files a user can have open at once; a hard limit is the maximum number of files the system can have open at once, computed from the system’s hardware resource status (mainly system memory). If neither -H nor -S is given, both the hard and soft limits are set at once. The value of limit can be a number, in the unit appropriate for the given resource, or one of the special values hard, soft, or unlimited, meaning respectively the current hard limit, the current soft limit, and no limit. If limit is omitted, the current soft limit for the resource is printed; the -H option prints the current hard limit. When more than one resource is specified, the limit name and unit are printed before the value.

Syntax

-H hard limit

-S soft limit

-a show all limits

-c core file size limit

-d process data segment size limit

-e scheduling priority limit

-f maximum file size the shell can create

-i pending signals limit

-l locked-memory limit

-m resident memory size limit

-n limit on the number of open files

-p pipe size limit

-q POSIX message queue limit

-r

-s stack size limit

-t limit on CPU time usable per second

-u limit on the number of processes

-v virtual memory limit

-x file lock limit

Configuration

  • /etc/security/limits.conf

Soft and hard limits on the number of open files at the Linux system user level

<domain> <type> <item> <value>

<domain>: the username to be restricted; prefix group names with @; use the wildcard * to match all users; root must be specified separately

<type>: soft is the soft limit. hard is the hard limit; the soft limit cannot be set higher than the hard limit

<item>:

core - limits the size of core dump files

date - maximum data size

fsize - maximum file size

memlock - maximum locked memory address space

nofile - maximum number of open files

rss - maximum resident set size

stack - maximum stack size

cpu - maximum CPU time, in minutes

noproc - maximum number of processes

as - address space limit

maxlogins - maximum number of logins allowed for this user

Example

Setting the maximum number of open files for user tomcat

tomcat soft nofile 10240
tomcat hard nofile 10240