ulimit Subroutine

Purpose

Sets and gets user limits.

Library

Standard C Library (libc.a)

Syntax

The syntax for the ulimit subroutine when the Command parameter specifies a value of GET_FSIZE or SET_FSIZE is:

#include <ulimit.h>

long int ulimit ( Command NewLimit)
int Command;
off_t NewLimit;

The syntax for the ulimit subroutine when the Command parameter specifies a value of GET_DATALIM, SET_DATALIM, GET_STACKLIM, SET_STACKLIM, GET_REALDIR, or SET_REALDIR is:

#include <ulimit.h>
long int ulimit (CommandNewLimit)
int Command;
unsigned long NewLimit;

Description

The ulimit subroutine controls process limits.

Even with remote files, the ulimit subroutine values of the process on the client node are used.

Note: Raising the data ulimit does not necessarily raise the program 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. Also, without these memory segments initialized, the value returned after such a change may not be the proper break value. If your data limit is RLIM_INFINITY, this value will never advance past the segment size, even if that data is available. Use the -bmaxdata flag of the ld command to set up these segments at load time.

Setting an fsize of 2G or more for a 32-bit application will be treated as unlimited.

Parameters

Item Description
Command Specifies the form of control. The following Command parameter values require that the NewLimit parameter be declared as an off_t structure:
GET_FSIZE (1)
Returns the process file size limit. The limit is in units of UBSIZE blocks (see the sys/param.h file) and is inherited by child processes. Files of any size can be read. The process file size limit is returned in the off_t structure specified by the NewLimit parameter.
SET_FSIZE (2)
Sets the process file size limit to the value in the off_t structure specified by the NewLimit parameter. Any process can decrease this limit, but only a process with root user authority can increase the limit. The new file size limit is returned.

The following Command parameter values require that the NewLimit parameter be declared as an integer:

GET_DATALIM (3)
Returns the maximum possible break value (as described in the brk or sbrk subroutine).
SET_DATALIM (1004)
Sets the maximum possible break value (described in the brk and sbrk subroutines). Returns the new maximum break value, which is the NewLimit parameter rounded up to the nearest page boundary.
Note: 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.
GET_STACKLIM (1005)
Returns the lowest valid stack address.
Note: Stacks grow from high addresses to low addresses.
SET_STACKLIM (1006)
Sets the lowest valid stack address. Returns the new minimum valid stack address, which is the NewLimit parameter rounded down to the nearest page boundary.
GET_REALDIR (1007)
Returns the current value of the real directory read flag. If this flag is a value of 0, a read system call (or readx with Extension parameter value of 0) against a directory returns fixed-format entries compatible with the System V UNIX operating system. Otherwise, a read system call(or readx with Extension parameter value of 0) against a directory returns the underlying physical format.
SET_REALDIR (1008)
Sets the value of the real directory read flag. If the NewLimit parameter is a value of 0, this flag is cleared; otherwise, it is set. The old value of the real directory read flag is returned.
NewLimit Specifies the new limit. The value and data type or structure of the NewLimit parameter depends on the Command parameter value that is used.

Examples

To increase the size of the stack by 4096 bytes (use 4096 or PAGESIZE), and set the rc to the new lowest valid stack address, enter:

rc = ulimit(SET_STACKLIM, ulimit(GET_STACKLIM, 0) - 4096);

Return Values

Upon successful completion, the value of the requested limit is returned. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.

All return values are permissible if the ulimit subroutine is successful. To check for error situations, an application should set the errno global variable to 0 before calling the ulimit subroutine. If the ulimit subroutine returns a value of -1, the application should check the errno global variable to verify that it is nonzero.

Error Codes

The ulimit subroutine is unsuccessful and the limit remains unchanged if one of the following is true:

Item Description
EPERM A process without root user authority attempts to increase the file size limit.
EINVAL The Command parameter is a value other than GET_FSIZE, SET_FSIZE, GET_DATALIM, SET_DATALIM, GET_STACKLIM, SET_STACKLIM, GET_REALDIR, or SET_REALDIR.