Go to the first, previous, next, last section, table of contents.
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.
This is also called the "soft limit".
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.
This is also called the "hard limit".
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 Operation Error Signals.
RLIMIT_FSIZE
-
The maximum size of file the process can create. Trying to write a
larger file causes a signal:
SIGXFSZ
. See section Operation Error 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 would dump a core file larger than this maximum size,
then no core file is created. So setting this limit to zero prevents
core files from ever being created.
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_MEMLOCK
-
The maximum amount of memory that can be locked into physical memory (so
it will never be paged out).
RLIMIT_NPROC
-
The maximum number of processes that can be created with the same user ID.
If you have reached the limit for your user ID,
fork
will fail
with EAGAIN
. See section Creating a Process.
RLIMIT_NOFILE
-
RLIMIT_OFILE
-
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. Not all systems support this limit; GNU does, and
4.4 BSD does.
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 first, previous, next, last section, table of contents.