getrlimit, setrlimit - Controls maximum system resource consumption
struct rlimit *rlp);
const struct rlimit *rlp);
[Digital] The following declaration of the setrlimit() function does not conform to current standards and is supported only for backward compatibility:
struct rlimit *rlp);
[Digital] Application developers may want to specify an #include statement for <sys/time.h> before the one for <sys/resource.h> if programs are being developed for multiple platforms. The additional #include statement is not required on Tru64 UNIX systems or by ISO or X/Open standards, but may be required on other vendors' systems that conform to these standards.
Interfaces documented on this reference page conform to industry standards as follows:
getrlimit(), setrlimit(): XPG4-UNIX
Refer to the standards(5) reference page for more information about industry standards and associated tags.
Specifies one of the following values: The maximum size, in bytes, of the total memory available to a process. Exceeding this limit causes the brk(), malloc(), mmap(), and sbrk() functions to fail with errno set to [ENOMEM]. Also, the automatic stack growth will fail with the effects described under RLIMIT_STACK. The largest size, in bytes, of a core file that can be created. A limit of 0 (zero) prevents the process from creating a core file. If a process exceeds this limit, any remaining data to be written to the core file is lost. The maximum amount of CPU time (in seconds) to be used by a process. If the process exceeds this limit, the system sends the SIGXCPU signal to the process. The maximum size, in bytes, of a process's data segment. Exceeding this limit causes the brk(), malloc(), mmap(), and sbrk() functions to fail with errno set to [ENOMEM]. The maximum size, in bytes, of any single file that can be created. A limit of 0 (zero) prevents the process from creating a file. If a write or truncate operation would cause this limit to be exceeded, the system generates the SIGXFSZ signal. If the process is blocking, catching, or ignoring SIGXFSZ, continued attempts to increase the size of a file from end-of-file to beyond the limit will fail with errno set to [EFBIG]. The maximum number of open file descriptors that the process can have. Any functions that attempt to create new file descriptors when the maximum hard limit has been reached will fail with errno set to [EMFILE].
The getrlimit() function obtains the limits on the consumption of system resources by the current process and each process it creates. You use the setrlimit() function to set these resources.
Each resource limit is specified as either a soft limit or a hard limit. When a soft limit is exceeded (for example, if the CPU time is exceeded), a process can receive a signal until it reaches the hard limit or until it modifies its resource limit. The rlimit structure is used to specify the hard and soft limits on a resource, as defined in the sys/resource.h header file.
The calling process must have superuser privilege in order to raise the maximum limits. An unprivileged process can alter the rlim_cur field of the rlimit structure within the range from 0 (zero) to rlim_max or can (irreversibly) lower rlim_max.
An infinite value for a limit is defined as RLIM_INFINITY.
Because this information is stored in the per-process information, and inherited by fork(), the setrlimit() function should be executed directly by the shell in order to affect all future processes created by the shell. Thus, limit is a built-in command to the shells.
The ulimit() function is implemented in terms of setrlimit(). Therefore, the two interfaces should not be used in the same program. The result of doing so is undefined.
[Digital] When compiled in the X/Open UNIX environment, calls to the setrlimit() function are internally renamed by prepending _E to the function name. When you are debugging a module that includes the setrlimit() function and for which _XOPEN_SOURCE_EXTENDED has been defined, use _Esetrlimit to refer to the setrlimit() call. See standards(5) for further information.
Upon successful completion, these functions return a value of 0 (zero). Otherwise, the functions return a value of -1 and set errno to indicate the error.
If the getrlimit() or setrlimit() function fails, errno might be set to one of the following values: [Digital] The address specified for the rlp parameter is invalid. An invalid resource was specified, or the new rlim_cur specified in a setrlimit() call exceeds the new rlim_max specified in that same call. The limit specified to the setrlimit() function would have raised the maximum limit value, and the calling process does not have appropriate privilege.
Functions: quotactl(2), setsysinfo(2), sigaction(2), sigstack(2), sigvec(2)
Standards: standards(5) delim off