Resource Limits

Resource limits, also known as rlimits or ulimits, configure the maximum resources a process and its children can consume, and persist accross execs.

Limits can be set on a number of dimensions including: virtual memory size (RLIMIT_AS), data segement size (RLIMIT_DATA), stack size (RLIMIT_STACK), CPU time (RLIMIT_CPU), and core dump file size (RLIMIT_CORE).

Hitting a limit manifests itself in different ways: Setting RLIMIT_CORE to 0 means core dump files aren’t created, hitting RLIMIT_CPU triggers a SIGXCPU, and hitting a memory limit leads to allocator errors.

Resource limits should be read and written via the ulimit bash builtin, prlimit, /proc/PID/limits, or prlimit64(2) (which replaced previous system calls).

CAP_SYS_RESOURCE is required to make changes to hard limits, but soft limits may be changed by unprivledged processes (within the bounds of the hard limits).

References