Go to the previous, next section.

Limiting Resource Usage

You can specify limits for the resource usage of a process. When the process tries to exceed a limit, it may get a signal, or the system call by which it tried to do so may fail, depending on the limit. Each process initially inherits its limit values from its parent, but it can subsequently change them.

The symbols in this section are defined in `sys/resource.h'.

Function: int getrlimit (int resource, struct rlimit *rlp)

Read the current value and the maximum value of resource resource and store them in *rlp.

The return value is 0 on success and -1 on failure. The only possible errno error condition is EFAULT.

Function: int setrlimit (int resource, struct rlimit *rlp)

Store the current value and the maximum value of resource resource in *rlp.

The return value is 0 on success and -1 on failure. The following errno error condition is possible:

EPERM
You tried to change the maximum permissible limit value, but you don't have privileges to do so.

Data Type: struct rlimit

This structure is used with getrlimit to receive limit values, and with setrlimit to specify limit values. It has two fields:

rlim_cur
The current value of the limit in question.

rlim_max
The maximum permissible value of the limit in question. You cannot set the current value of the limit to a larger number than this maximum. Only the super user can change the maximum permissible value.

In getrlimit, the structure is an output; it receives the current values. In setrlimit, it specifies the new values.

Here is a list of resources that you can specify a limit for. Those that are sizes are measured in bytes.

RLIMIT_CPU
The maximum amount of cpu time the process can use. If it runs for longer than this, it gets a signal: SIGXCPU. The value is measured in seconds. See section Nonstandard Signals.

RLIMIT_FSIZE
The maximum size of file the process can create. Trying to write a larger file causes a signal: SIGXFSZ. See section Nonstandard Signals.

RLIMIT_DATA
The maximum size of data memory for the process. If the process tries to allocate data memory beyond this amount, the allocation function fails.

RLIMIT_STACK
The maximum stack size for the process. If the process tries to extend its stack past this size, it gets a SIGSEGV signal. See section Program Error Signals.

RLIMIT_CORE
The maximum size core file that this process can create. If the process terminates and a core file is made, and this maximum size is not enough, the core file is truncated.

RLIMIT_RSS
The maximum amount of physical memory that this process should get. This parameter is a guide for the system's scheduler and memory allocator; the system may give the process more memory when there is a surplus.

RLIMIT_OPEN_FILES
The maximum number of files that the process can open. If it tries to open more files than this, it gets error code EMFILE. See section Error Codes.

RLIM_NLIMITS
The number of different resource limits. Any valid resource operand must be less than RLIM_NLIMITS.

Constant: int RLIM_INFINITY

This constant stands for a value of "infinity" when supplied as the limit value in setrlimit.

Two historical functions for setting resource limits, ulimit and vlimit, are not documented here. The latter is declared in `sys/vlimit.h' and comes from BSD.

Go to the previous, next section.