getrlimit(2) getrlimit(2)
NAME
getrlimit, setrlimit - control maximum system resource con-
sumption
SYNOPSIS
#include <sys/time.h>
#include <sys/resource.h>
int getrlimit(int resource, struct rlimit *rlp);
int setrlimit(int resource, const struct rlimit *rlp);
DESCRIPTION
Limits on the consumption of a variety of system resources
by a process and each process it creates may be obtained
with getrlimit and set with setrlimit.
Each call to either getrlimit or setrlimit identifies a
specific resource to be operated upon as well as a resource
limit. A resource limit is a pair of values: one specify-
ing the current (soft) limit, the other a maximum (hard)
limit. Soft limits may be changed by a process to any value
that is less than or equal to the hard limit. A process may
(irreversibly) lower its hard limit to any value that is
greater than or equal to the soft limit. Only a process
with an effective user ID or superuser can raise a hard
limit. Both hard and soft limits can be changed in a single
call to setrlimit subject to the constraints described
above. Limits may have an infinite value of RLIM_INFINITY.
rlp is a pointer to struct rlimit that includes the follow-
ing members:
rlim_t rlim_cur; /* current (soft) limit */
rlim_t rlim_max; /* hard limit */
rlim_t is an arithmetic data type to which objects of type
int, size_t, and off_t can be cast without loss of informa-
tion.
The possible resources, their descriptions, and the actions
taken when current limit is exceeded, are summarized in the
table below:
Resources Description Action
_______________________________________________
RLIMIT_CORE The maximum The writing of
size of a core a core file
file in bytes will terminate
that may be at this size.
created by a
process. A
limit of 0 will
prevent the
Page 1 CX/UX Programmer's Reference Manual
getrlimit(2) getrlimit(2)
creation of a
core file.
RLIMIT_CPU The maximum SIGXCPU is sent
amount of CPU to the process.
time in seconds If the process
used by a pro- is holding or
cess. ignoring
SIGXCPU, the
behavior is
scheduling
class defined.
RLIMIT_DATA The maximum brk(2) will
size of a fail with errno
process's heap set to ENOMEM.
in bytes.
Page 2 CX/UX Programmer's Reference Manual
getrlimit(2) getrlimit(2)
Resources Description Action
_________________________________________________
RLIMIT_FSIZE The maximum SIGXFSZ is sent
size of a file to the process.
in bytes that If the process
may be created is holding or
by a process. ignoring
A limit of 0 SIGXFSZ, con-
will prevent tinued attempts
the creation of to increase the
a file. size of a file
beyond the
limit will fail
with errno set
to EFBIG.
RLIMIT_NOFILE The maximum Functions that
number of open create new file
file descrip- descriptors
tors that the will fail with
process can errno set to
have. EMFILE.
RLIMIT_STACK The maximum SIGSEGV is sent
size of a to the process.
process's stack If the process
in bytes. The is holding or
system will not ignoring SIG-
automatically SEGV, or is
grow the stack catching SIG-
beyond this SEGV and has
limit. not made
arrangements to
use an alter-
nate stack [see
sigaltstack(2)
and sigac-
tion(2) or sig-
stack(2) and
sigvec(2)], the
disposition of
SIGSEGV will be
set to SIG_DFL
before it is
sent.
Because limit information is stored in the per-process
information, the shell builtin ulimit must directly execute
this system call if it is to affect all future processes
created by the shell.
RETURN VALUE
Upon successful completion, the function getrlimit returns a
value of 0; otherwise, it returns a value of -1 and sets
Page 3 CX/UX Programmer's Reference Manual
getrlimit(2) getrlimit(2)
errno to indicate an error.
ERRORS
Under the following conditions, the functions getrlimit and
setrlimit fail and set errno to:
EINVAL if an invalid resource was specified; or in a
setrlimit call, the new rlim_cur exceeds the new
rlim_max.
EPERM if the limit specified to setrlimit would have raised
the maximum limit value, and the caller is not the
superuser.
SEE ALSO
malloc(3C), open(2), sigaltstack(2), sigvec(2), sigset(2).
Page 4 CX/UX Programmer's Reference Manual