[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

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.

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.

Parameters

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 (CPU) time, in seconds, to be used by each process. If a process exceeds its soft CPU limit, the kernel will send a SIGXCPU signal to the process.
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.
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.
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.

Error Codes

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

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.

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

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

Related Information

The sigaction, sigvec, or signal subroutines, sigstack subroutine, ulimit subroutine.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]