Resources usage can be limited using the setrlimit() function
described below. Each resource is controlled by a pair of limits: a
soft limit and a hard limit. The soft limit is the current limit, and
may be lowered or raised by a process over time. The soft limit can
never exceed the hard limit. The hard limit can be lowered to any
value greater than the soft limit, but not raised. (Only processes with
the effective UID of the super-user can raise a hard limit.)
The specific resources that can be limited are system dependent. They
are described in the getrlimit(2) man page. The resources
listed below are supported when the underlying operating system
supports them; resources which cannot be checked or controlled by the
operating system are not defined in this module for those platforms.
- getrlimit (resource)
Returns a tuple (soft, hard) with the current
soft and hard limits of resource. Raises ValueError if
an invalid resource is specified, or error if the
underyling system call fails unexpectedly.
- setrlimit (resource, limits)
Sets new limits of consumption of resource. The limits
argument must be a tuple (soft, hard) of two
integers describing the new limits. A value of -1 can be used to
specify the maximum possible upper limit.
Raises ValueError if an invalid resource is specified,
if the new soft limit exceeds the hard limit, or if a process tries
to raise its hard limit (unless the process has an effective UID of
super-user). Can also raise error if the underyling
system call fails.
These symbols define resources whose consumption can be controlled
using the setrlimit() and getrlimit() functions
described below. The values of these symbols are exactly the constants
used by C programs.
The Unix man page for getrlimit(2) lists the available
resources. Note that not all systems use the same symbol or same
value to denote the same resource.
The maximum size (in bytes) of a core file that the current process
can create. This may result in the creation of a partial core file
if a larger core would be required to contain the entire process
The maximum amount of CPU time (in seconds) that a process can
use. If this limit is exceeded, a SIGXCPU signal is sent to
the process. (See the signal module documentation for
information about how to catch this signal and do something useful,
e.g. flush open files to disk.)
The maximum size of a file which the process may create. This only
affects the stack of the main thread in a multi-threaded process.
The maximum size (in bytes) of the process's heap.
The maximum size (in bytes) of the call stack for the current
The maximum resident set size that should be made available to the
The maximum number of processes the current process may create.
The maximum number of open file descriptors for the current
The BSD name for RLIMIT_NOFILE.
The maximm address space which may be locked in memory.
The largest area of mapped memory which the process may occupy.
The maximum area (in bytes) of address space which may be taken by
Send comments on this document to firstname.lastname@example.org.