getrlimit(2)
NAME
getrlimit, setrlimit − control consumption of system resources
SYNOPSIS
#include <sys/resource.h>
int getrlimit(int resource, struct rlimit *rlp);
int setrlimit(int resource, const struct rlimit *rlp);
DESCRIPTION
setrlimit() sets a limit on consumption of system resources by the current process and each process it creates. getrlimit() is used to obtain the value of the current limit.
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 can be changed by a process to any value that is less than or equal to the hard limit. A process can irreversibly lower its hard limit to any value that is greater than or equal to the soft limit. Only users with appropriate privileges 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.
The resource parameter selects the system resource limits to be set or retrieved. The possible values for resource are defined in <sys/resource.h>. Currently, only the following values are supported:
RLIMIT_NOFILE the maximum number of files a process can have open. The soft limit for this resource is the same as the value returned by sysconf(_SC_OPEN_MAX).
RLIMIT_OPEN_MAX defined to be the same as RLIMIT_NOFILE.
The rlp argument points to an object of type struct rlimit, which is defined in <sys/resource.h>, and includes the following members:
int rlim_cur Current (soft) limit
int rlim_max Hard limit
For getrlimit(), the system stores the two limits on the specified resource in the structure to which rlp points.
For setrlimit(), the system reads new values for the two limits on the specified resource from the structure to which rlp points.
RETURN VALUE
Upon successful completion, getrlimit() and setrlimit() return a value of 0. Otherwise, a value of −1 is returned, the limits on the resource and the rlp structure are unchanged, and errno is set to indicate the error.
ERRORS
getrlimit() and setrlimit() fail if:
[EFAULT] The address specified for rlp is invalid. Reliable detection of this error is implementation dependent.
[EINVAL] The number specified for resource is invalid.
setrlimit fails if:
[EPERM]
The rlp argument specified a hard or soft limit higher than the current hard limit value, and the caller does not have appropriate privileges.
[EINVAL] A user with appropriate privileges has attempted to raise rlp−>rlim_cur or rlp−>rlim_max to a value greater than the system is capable of supporting.
[EINVAL] The value of rlp−>rlim_cur is less than the number of file descriptors the process already has allocated.
[EINVAL] The value of rlp−>rlim_max is less than the current soft limit.
AUTHOR
getrlimit() and setrlimit() were developed by HP, AT&T, and the University of California, Berkeley.
SEE ALSO
Hewlett-Packard Company — HP-UX Release 9.0: August 1992