getrlimit(2) getrlimit(2) NAME getrlimit, getrlimit64, setrlimit, setrlimit64 - control maximum system resource consumption SYNOPSIS #include <sys/resource.h> int getrlimit(int resource, struct rlimit *rlp); int getrlimit64(int resource, struct rlimit64 *rlp); int setrlimit(int resource, const struct rlimit *rlp); int setrlimit64(int resource, const struct rlimit64 *rlp); DESCRIPTION Limits on the consumption of a variety of system resources by a process and each process it creates may be obtained with getrlimit and set with setrlimit. getrlimit64 and setrlimit64 allow 32-bit programs to set 64-bit limits. This is particularly useful for shells and other 32-bit programs which fork 64-bit binaries. Unless otherwise specified, getrlimit64 and setrlimit64 function in exactly the same manner as getrlimit and setrlimit. Each call to either getrlimit or setrlimit identifies a specific resource to be operated upon as well as a resource limit. A resource limit is a pair of values: one specifying the current (soft) limit, the other a maximum (hard) limit. Soft limits may be changed by a process to any value that is less than or equal to the hard limit. A process may (irreversibly) lower its hard limit to any value that is greater than or equal to the soft limit. Only a the super-user can raise a hard limit. Both hard and soft limits can be changed in a single call to setrlimit subject to the constraints described above. getrlimit64 and setrlimit64 are provided to allow 32 bit applications to manipulate 64 bit limit values. For example, the RLIMIT_FSIZE can be set as large as 0xffffffffff with setrlimit64 when using the xfs filesystem. When using the 32 bit interfaces, limits may have an infinite value of RLIM_INFINITY (0x7fffffff). In this case rlp is a pointer to struct rlimit that includes the following members: rlim_t rlim_cur; /* current (soft) limit */ rlim_t rlim_max; /* hard limit */ rlim_t is an arithmetic data type to which objects of type int, size_t, and off_t can be cast without loss of information. Specifying the RLIM_INFINITY value as the limit in a setrlimit call may allow the value of the resource to exceed 0x7fffffff. This is because specifying RLIM_INFINITY as the limit indicates to the system to use no limit other than that imposed by the operating system. When getrlimit is used to retrieve a limit which has a value greater than that which can be represented by an rlim_t, the value returned is the maximum value representable by an rlim_t. This value is currently UINT_MAX. When using the 64 bit interfaces, limits may have an infinite value of RLIM64_INFINITY (0x7fffffffffffffff). In this case rlp is a pointer to struct rlimit64 that includes the following members: rlim64_t rlim_cur;/* current (soft) limit */ rlim64_t rlim_max;/* hard limit */ rlim64_t is an arithmetic data type to which objects of type long long and off64_t can be cast without loss of information. The possible resources, their descriptions, and the actions taken when current limit is exceeded, are summarized below: RLIMIT_CORE The maximum size of a core file in bytes that may be created by a process. A limit of 0 will prevent the creation of a core file. The writing of a core file will terminate at this size. RLIMIT_CPU The maximum amount of CPU time in seconds used by a process. SIGXCPU is sent to a process which exceeds this limit. If the process is holding or ignoring SIGXCPU, the behavior is scheduling class defined. Unless the SVR4_SIGNALS variable in /etc/default/login is set to NO, this signal will be ignored by default. RLIMIT_DATA The maximum size of a process's heap in bytes. A brk(2) which attempts to exceed this limit will fail with errno set to ENOMEM. RLIMIT_FSIZE The maximum size of a file in bytes that may be created by a process. A limit of 0 will prevent the creation of a file. A process which attempts to exceed this limit will fail with errno set to SIGXFSZ. If the process is holding or ignoring SIGXFSZ, continued attempts to increase the size of a file beyond the limit will fail with errno set to EFBIG. Unless the SVR4_SIGNALS variable in /etc/default/login is set to NO, this signal will be ignored by default. RLIMIT_NOFILE The maximum number of open file descriptors that the process can have. Functions that attempt to create new file descriptors beyond this limit will fail with errno set to EMFILE. If the systune(1) variable rlimit_nofile_cur_clamps_setrlimit is non-zero, any attempt to set RLIMIT_NOFILE to a value lower than existing open file descriptors will fail with errno set to EINVAL. RLIMIT_STACK The maximum size of a process's stack in bytes. SIGSEGV is sent to a process which attempts to exceed this limit. If the process is holding or ignoring SIGSEGV, or is catching SIGSEGV and has not made arrangements to use an alternate stack [see sigaltstack(2)], the disposition of SIGSEGV will be set to SIG_DFL before it is sent. This value is used as the default stacksize by sproc(2). RLIMIT_VMEM The maximum size of a process's mapped address space in bytes. brk(2) and mmap(2) functions which attempt to exceed this limit will fail with errno set to ENOMEM. In addition, the automatic stack growth will fail with the effects outlined above. RLIMIT_RSS The maximum size, in bytes to which a process's resident set size may grow. This imposes a limit on the amount of physical memory to be given to a process; if memory is tight, the system will prefer to take memory from processes that are exceeding their declared resident set size. RLIMIT_PTHREAD The maximum number of threads (pthreads(5)) that a process may create. Functions that attempt to create new threads beyond this limit will fail with the error EAGAIN. Because limit information is stored in the per-process information, the shell builtin ulimit must directly execute this system call if it is to affect all future processes created by the shell; limit is thus a built- in command to sh(1) and csh(1). The value of the current limit of the following resources affect these implementation defined constants: Limit Implementation Defined Constant _______________________________________________ RLIMIT_NOFILE OPEN_MAX RETURN VALUE Upon successful completion, the function getrlimit returns a value of 0; otherwise, it returns a value of -1 and sets errno to indicate an error. ERRORS Under the following conditions, the functions getrlimit and setrlimit fail and set errno to: [EFAULT] The address specified for rlp in invalid. [EINVAL] if an invalid resource was specified; or in a setrlimit call, the new rlim_cur exceeds the new rlim_max. [EPERM] if the limit specified to setrlimit would have raised the maximum limit value and the caller is not the super-user. SEE ALSO csh(1), sh(1), systune(1), open(2), sigaltstack(2), malloc(3C), signal(5). Page 4