getrlimit, setrlimit

Name

getrlimit, setrlimit -- get resource consumption limits

Synopsis

#include <sys/resource.h>

int getrlimit(__rlimit_resource_t __resource, struct rlimit * __rlimits);

int setrlimit(__rlimit_resource_t __resource, const struct rlimit * __rlimits);

Description

getrlimit() and setrlimit() are as specified in POSIX 1003.1-2008 (ISO/IEC 9945-2009), but with differences as listed below.

Extra Resources

These additional resources extend the list in POSIX 1003.1-2008 (ISO/IEC 9945-2009).

RLIMIT_NPROC 

The maximum number of processes (or, more precisely on Linux, threads) that can be created for the real user ID of the calling process. Upon encountering this limit, fork() shall fail with the error EAGAIN.

RLIMIT_MEMLOCK 

The maximum number of bytes of memory that may be locked into RAM. In effect this limit is rounded down to the nearest multiple of the system page size. This limit affects mlock() and mlockall(), the mmap() MAP_LOCKED operation and the shmctl() SHM_LOCK operation. The shmctl() SHM_LOCK locks are accounted for separately from the per-process memory locks established by mlock(), mlockall(), and mmap() MAP_LOCKED. In the former case, the limit sets a maximum on the total bytes in shared memory segments (see shmget()) that may be locked by the real user ID of the calling process. A process can lock bytes up to this limit in each of these two categories.

RLIMIT_LOCKS 

A limit on the combined number of flock() locks and fcntl() leases that this process may establish. This limit is obsolete and should not be used; support depends heavily on the version of the operating system kernel.

RLIMIT_RSS 

Specifies the limit (in pages) of the process's resident set. This limit is obsolete and should not be used; support depends heavily on the version of the operating system kernel. It affects only calls to madvise() specifying MADV_WILLNEED.

RLIMIT_SIGPENDING 

Specifies the limit on the number of signals that may be queued for the real user ID of the calling process. Both standard and real-time signals are counted for the purpose of checking this limit. However, the limit is enforced only for sigqueue(); it is always possible to use kill() to queue one instance of any of the signals that are not already queued to the process.

RLIMIT_MSGQUEUE 

Specifies the limit on the number of bytes that can be allocated for POSIX message queues for the real user ID of the calling process. This limit is enforced for mq_open(). Each message queue that the user creates counts (until it is removed) against this limit according to the formula:

  bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
	  attr.mq_maxmsg * attr.mq_msgsize

where attr is the mq_attr structure specified as the fourth argument to mq_open(3).

The first addend in the formula, which includes sizeof(struct msg_msg *) (4 bytes on Linux/i386), ensures that the user cannot create an unlimited number of zero-length messages (such messages nevertheless each consume some system memory for bookkeeping overhead).

RLIMIT_NICE 

Specifies a ceiling to which the process's nice value can be raised using setpriority() or nice(). The actual ceiling for the nice value is calculated as 20 minus the value of rlim_cur.

RLIMIT_RTPRIO 

Specifies a ceiling on the real-time priority that may be set for this process using sched_setscheduler(2) and sched_setparam(2).

RLIMIT_RTTIME 

Specifies a limit (in microseconds) on the amount of CPU time that a process scheduled under a real-time scheduling policy may consume without making a blocking system call. For the purpose of this limit, each time a process makes a blocking system call, the count of its consumed CPU time is reset to zero. The CPU time count is not reset if the process continues trying to use the CPU but is preempted, its time slice expires, or it calls sched_yield().

Upon reaching the soft limit, the process is sent a SIGXCPU signal. If the process catches or ignores this signal and continues consuming CPU time, then SIGXCPU will be generated once each second until the hard limit is reached, at which point the process is sent a SIGKILL signal.

The intended use of this limit is to stop a runaway real-time process from locking up the system.

Extra Errors

These additional error codes extend the list in POSIX 1003.1-2008 (ISO/IEC 9945-2009).

EFAULT 

A pointer argument points to a location outside the accessible address space.