getrlimit(2) getrlimit(2)
NAME
getrlimit, setrlimit - control maximum system resource
consumption
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 specifying
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.
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 following 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
information.
The possible resources, their descriptions, and the actions
taken when current limit is exceeded, are summarized in the
table below:
Copyright 1994 Novell, Inc. Page 1
getrlimit(2) getrlimit(2)
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
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 is holding or
process. 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.
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,
will prevent continued
the creation of attempts to
a file. increase the
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 descriptors
Copyright 1994 Novell, Inc. Page 2
getrlimit(2) getrlimit(2)
descriptors will fail with
that the errno set to
process can EMFILE.
have.
RLIMIT_STACK The maximum SIGSEGV is sent
size of a to the
process's offending
single autogrow thread. If
stack in bytes. that thread is
The system will holding SIGSEGV
not or if the
automatically containing
grow the stack process is
beyond this ignoring
limit. SIGSEGV or is
catching
SIGSEGV and the
underlying LWP
has not made
arrangements to
use an
alternate stack
[see
sigaltstack(2)],
the disposition
of SIGSEGV will
be set to
SIG_DFL before
it is sent.
Consequently,
the containing
process is
terminated.
RLIMIT_VMEM The maximum brk(2) and
size of a mmap(2)
process's functions will
mapped address fail with errno
space in bytes. set to ENOMEM.
In addition,
the automatic
stack growth
will fail with
the effects
outlined above.
Copyright 1994 Novell, Inc. Page 3
getrlimit(2) getrlimit(2)
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.
The value of the current limit of the following resources
affect these implementation defined constants:
Limit Implementation Defined Constant
_______________________________________________
RLIMIT_FSIZE FCHR_MAX
RLIMIT_NOFILE OPEN_MAX
Return Values
On success, getrlimit returns 0. On failure, getrlimit
returns -1 and sets errno to identify the error.
Errors
Under the following conditions, the functions getrlimit and
setrlimit fail and set errno to:
EINVAL An invalid resource was specified; or in a setrlimit
call, the new rlim_cur exceeds the new rlim_max.
EPERM The limit specified to setrlimit would have raised the
maximum limit value and the calling process does not
have appropriate privilege (P_SYSOPS).
REFERENCES
malloc(3C), open(2), sigaltstack(2), signal(5)
NOTICES
Considerations for Threads Programming
These resource limits are an attribute of the containing
process and are shared by sibling threads.
Also, see description of RLIMIT_STACK above.
Copyright 1994 Novell, Inc. Page 4