getrlimit, getrlimit64, setrlimit, setrlimit64, or vlimit Subroutine

Purpose

Controls maximum system resource consumption.

Library

Standard C Library (libc.a)

Syntax

#include <sys/time.h>
#include <sys/resource.h>

int setrlimit( Resource1, RLP)
int Resource1;
struct rlimit *RLP;

int setrlimit64 ( Resource1, RLP)
int Resource1;
struct rlimit64 *RLP;

int getrlimit ( Resource1, RLP)
int Resource1;
struct rlimit *RLP;

int getrlimit64 ( Resource1, RLP)
int Resource1;
struct rlimit64 *RLP;

#include <sys/vlimit.h>

vlimit ( Resource2, Value)
int Resource2, Value;

Description

The getrlimit subroutine returns the values of limits on system resources used by the current process and its children processes. The setrlimit subroutine sets these limits. The vlimit subroutine is also supported, but the getrlimit subroutine replaces it.

A resource limit is specified as either a soft (current) or hard limit. A calling process can raise or lower its own soft limits, but it cannot raise its soft limits above its hard limits. A calling process must have root user authority to raise a hard limit.

Note: The initial values returned by the getrlimit subroutine are the ulimit values in effect when the process was started. For maxdata programs the initial value returned by getrlimit for the soft data limit is the lower of the hard data limit or the maxdata value. When a program is executing using the large address-space model, the operating system attempts to modify the soft limit on data size, if necessary, to increase it to match the maxdata value. If the maxdata value is larger than the current hard limit on data size, either the program will not execute if the XPG_SUS_ENV environment variable has the value set to ON, or the soft limit will be set to the current hard limit. If the maxdata value is smaller than the size of the program's static data, the program will not execute.

The rlimit structure specifies the hard and soft limits for a resource, as defined in the sys/resource.h file. The RLIM_INFINITY value defines an infinite value for a limit.

When compiled in 32-bit mode, RLIM_INFINITY is a 32-bit value; when compiled in 64-bit mode, it is a 64-bit value. 32-bit routines should use RLIM64_INFINITY when setting 64-bit limits with the setrlimit64 routine, and recognize this value when returned by getrlimit64.

This information is stored as per-process information. This subroutine must be executed directly by the shell if it is to affect all future processes created by the shell.

Note: Raising the data limit does not raise the program break value. Use the brk/sbrk subroutines to raise the break value. If the proper memory segments are not initialized at program load time, raising your memory limit will not allow access to this memory. Use the -bmaxdata flag of the ld command to set up these segments at load time.

When compiled in 32-bit mode, the struct rlimit values may be returned as RLIM_SAVED_MAX or RLIM_SAVED_CUR when the actual resource limit is too large to represent as a 32-bit rlim_t.

These values can be used by library routines which set their own rlimits to save off potentially 64-bit rlimit values (and prevent them from being truncated by the 32-bit struct rlimit). Unless the library routine intends to permanently change the rlimits, the RLIM_SAVED_MAX and RLIM_SAVED_CUR values can be used to restore the 64-bit rlimits.

Application limits may be further constrained by available memory or implementation defined constants such as OPEN_MAX (maximum available open files).

Parameters

Item Description
Resource1 Can be one of the following values:
RLIMIT_AS
The maximum size of a process' total available memory, in bytes. This limit is not enforced.
RLIMIT_CORE
The largest size, in bytes, of a core file that can be created. This limit is enforced by the kernel. If the value of the RLIMIT_FSIZE limit is less than the value of the RLIMIT_CORE limit, the system uses the RLIMIT_FSIZE limit value as the soft limit.
RLIMIT_CPU
The maximum amount of central processing unit (processor) time, in seconds, to be used by each process. If a process exceeds its soft processor limit, the kernel will send a SIGXCPU signal to the process. After the hard limit is reached, the process will be killed with SIGXCPU, even if it handles, blocks, or ignores that signal.
RLIMIT_DATA
The maximum size, in bytes, of the data region for a process. This limit defines how far a program can extend its break value with the sbrk subroutine. This limit is enforced by the kernel. If the XPG_SUS_ENV=ON environment variable is set in the user's environment before the process is executed and a process attempts to set the limit lower than current usage, the operation fails with errno set to EINVAL. If the XPG_SUS_ENV environment variable is not set, the operation fails with errno set to EFAULT.
RLIMIT_FSIZE
The largest size, in bytes, of any single file that can be created. When a process attempts to write, truncate, or clear beyond its soft RLIMIT_FSIZE limit, the operation will fail with errno set to EFBIG. If the environment variable XPG_SUS_ENV=ON is set in the user's environment before the process is executed, then the SIGXFSZ signal is also generated.
RLIMIT_NOFILE
This is a number one greater than the maximum value that the system may assign to a newly-created descriptor.
RLIMIT_STACK
The maximum size, in bytes, of the stack region for a process. This limit defines how far a program stack region can be extended. Stack extension is performed automatically by the system. This limit is enforced by the kernel. When the stack limit is reached, the process receives a SIGSEGV signal. If this signal is not caught by a handler using the signal stack, the signal ends the process.
RLIMIT_RSS
The maximum size, in bytes, to which the resident set size of a process can grow. This limit is not enforced by the kernel. A process may exceed its soft limit size without being ended.
RLIMIT_THREADS
The maximum number of threads each process can create. This limit is enforced by the kernel and the pthread library.
RLIMIT_NPROC
The maximum number of processes each user can create.
RLP Points to the rlimit or rlimit64 structure, which contains the soft (current) and hard limits. For the getrlimit subroutine, the requested limits are returned in this structure. For the setrlimit subroutine, the desired new limits are specified here.
Resource2 The flags for this parameter are defined in the sys/vlimit.h, and are mapped to corresponding flags for the setrlimit subroutine.
Value Specifies an integer used as a soft-limit parameter to the vlimit subroutine.

Return Values

On successful completion, a return value of 0 is returned, changing or returning the resource limit. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error. If the current limit specified is beyond the hard limit, the setrlimit subroutine sets the limit to max limit and returns successfully.

Error Codes

The getrlimit, getrlimit64, setrlimit, setrlimit64, or vlimit subroutine is unsuccessful if one of the following is true:

Item Description
EFAULT The address specified for the RLP parameter is not valid.
EINVAL The Resource1 parameter is not a valid resource, or the limit specified in the RLP parameter is invalid.
EPERM The limit specified to the setrlimit subroutine would have raised the maximum limit value, and the caller does not have root user authority.