This call limits the use of a variety of resources via a process and all its child processes;
getrlimit()
reads the limits and setrlimit()
sets them.
Each getrlimit()
or setrlimit()
call specifies a particular resource resource and a particular limit for it which is referenced by rlp. The limit comprises a pair of values located in the rlimit
structure. rlp must be a pointer to such a structure. rlimit
contains the following components:
rlim_t
| rlim_cur;
| /* Current limit */
|
rlim_t
| rlim_max;
| /* Maximum limit */
|
rlim_t
is an arithmetical data type to which objects of types int
, size_t
and off_t
can be converted without information getting lost. rlim_cur
specifies the current or soft limit, rlim_max
the maximum or hard limit. Soft limits can be set by a process to a value that is less than or equal to the hard limit. A process can reduce its hard limit (this is not reversible), so that it becomes greater than or equal to the soft limit. Only a process with the appropriate privileges can increase a hard limit. Both hard and soft limits can be changed by a single setrlimit()
call, taking the above restrictions into account.
The RLIM_INFINITY
value, which is defined in sys/resource.h
, is equivalent to an infinitely large limit, i.e. if getrlimit()
returns RLIM_INFINITY
for a resource, the implementation does not allow for a limit for this resource. If setrlimit()
with RLIM_INFINITY
is successfully executed for a resource, it is no longer checked whether this resource complies with this value.
If the limit for a resource is correctly represented in an object of type rlimit_t
when the getrlimit()
function is used, then this representation is returned. However, if the limit for the parameter is equal to the saved limit , then the value RLIM_SAVED_MAX
is returned. Otherwise the value RLIM_SAVED_CUR
is returned.
If the requested limit is RLIM_INFINITY
for the setrlimit()
function, then no value is intended for the new limit. If the requested limit is RLIM_SAVED_MAX
, the new limit is the saved hard limit. If RLIM_SAVED_CUR
is requested as the limit , the new limit is the saved
soft limit. Otherwise the new value is the requested value. Furthermore, the corresponding saved limit is overwritten by the new limit if it can be correctly represented in an object of type rlim_t
.
If a limit is set to RLIM_SAVED_MAX
or RLIM_SAVED_CUR
, the result is undefined unless an earlier getrlimit()
call returned this value as the hard or soft limit for the corresponding resource limit.
The same also applies to the getrlimit64()
, setrlimit64()
functions and to the RLIM64_INFINITY
, RLIM64_SAVED_MAX
and RLIM64_SAVED_CUR
values.
The following table lists the possible resources with their descriptions and the resulting measures when a limit is exceeded:
Resource | Description | Measure |
RLIMIT_CORE
| Maximum size of a core dump file in bytes that can be generated by a process. A size of 0 prevents the generation of memory dump files. | Writing of a core dump file ceases when this size is reached. |
RLIMIT_CPU
| Maximum CPU time used by a process. | SIGXCPU is sent to the process. If the process blocks, catches or ignores SIGXCPU , the behavior is undefined.
|
RLIMIT_DATA
| Maximum size of the data segment of a process in bytes. Under POSIX the size is unlimited, because sbrk() , brk() and malloc() use independent memory. | brk (), malloc() and sbrk() will fail and errno will contain ENOMEM .
|
RLIMIT_FSIZE
| Maximum length of a file in bytes that can be generated by a process. A length of 0 prevents files from being generated. | SIGXFSZ is sent to the process. If the process blocks, catches or ignores SIGXFSZ , further attempts to enlarge the file will fail and errno will contain EFBIG .
|
RLIMIT_NOFILE
| Maximum number of open file descriptors that a process can have. | Functions which create new file descriptors will fail and errno will contain EMFILE. |
RLIMIT_STACK
| Maximum size of the process stack in bytes. The system does not let the stack grow automatically beyond this limit. | SIGSEGV is sent to the process. If the process blocks, ignores or catches SIGSEGV and does not use an alternative stack (see sigaltstack() ), SIG_DFL is set as the handling mode of SIGSEGV .
|
RLIMIT_AS
| Maximum length of the address area of a process in bytes. | The functions brk() , malloc() , mmap() and sbrk() will fail and errno will contain ENOMEM . Also, the stack can no longer increase and the above-mentioned effects occur. |
As the limit information is managed for each process, the shell statement ulimit
must execute this system call directly in order to influence all future processes that are generated by the shell.
The value of the current limit of the following resources influences these implementationdependent constants:
Limit | Implementation-dependent constant |
RLIMIT_FSIZE
| FCHR_MAX
|
RLIMIT_NOFILE
| OPEN_MAX
|
There is no difference in functionality between getrlimit()
/ setrlimit()
and getrlimit64()
/ setrlimit64()
except that getrlimit64()
and setrlimit64()
use a rlimit64
structure.
The rlimit64
structure is defined in the same manner as rlimit
:
rlim64_t rlim_cur
rlim64_t rlim_max
If threads are used, then the function affects the process or a thread in the following manner:
RLIMIT_CPU
: ... if the process traps or ignores the SIGXCPU
signal or all threads belonging to this process block this signal, then the behavior is undefined.
RLIMIT_FSIZE
: ... the SIGXFSZ
signal is generated for the thread. If the thread blocks the SIGXFSZ
signal or the process traps or ignores this signal, further attempts to increase the size of the file will fail and errno
is set to EFBIG
.
RLIMIT_STACK
:... the SIGSEGV
signal is generated for the thread. If the thread blocks the SIGSEGV
signal or the process traps or ignores this signal and does not use an alternative stack, the SIG_DFL
handling mode of SIGSEGV SIG_DFL
is set.