<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>8.11.1 Resource Limits</TITLE>
<META NAME="description" CONTENT="8.11.1 Resource Limits">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="node168.html">
<LINK REL="previous" HREF="module-resource.html">
<LINK REL="up" HREF="module-resource.html">
<LINK REL="next" HREF="node168.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="node168.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-resource.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-resource.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="node168.html">8.11.2 Resource Usage</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-resource.html">8.11 resource  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-resource.html">8.11 resource  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00101110000000000000000">
8.11.1 Resource Limits</A>
</H2>

<P>
Resources usage can be limited using the <tt class=function>setrlimit()</tt> 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.)

<P>
The specific resources that can be limited are system dependent. They
are described in the <span class=manpage><i>getrlimit</i>(2)</span> 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.

<P>
<dl><dt><b><a name="l2h-1510"><tt class=function>getrlimit</tt></a></b> (<var>resource</var>)
<dd>
  Returns a tuple <tt>(<var>soft</var>, <var>hard</var>)</tt> with the current
  soft and hard limits of <var>resource</var>. Raises <tt class=exception>ValueError</tt> if
  an invalid resource is specified, or <tt class=exception>error</tt> if the
  underyling system call fails unexpectedly.
</dl>

<P>
<dl><dt><b><a name="l2h-1511"><tt class=function>setrlimit</tt></a></b> (<var>resource, limits</var>)
<dd>
  Sets new limits of consumption of <var>resource</var>. The <var>limits</var>
  argument must be a tuple <tt>(<var>soft</var>, <var>hard</var>)</tt> of two
  integers describing the new limits. A value of <tt>-1</tt> can be used to
  specify the maximum possible upper limit.

<P>
Raises <tt class=exception>ValueError</tt> 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 <tt class=exception>error</tt> if the underyling
  system call fails.
</dl>

<P>
These symbols define resources whose consumption can be controlled
using the <tt class=function>setrlimit()</tt> and <tt class=function>getrlimit()</tt> functions
described below. The values of these symbols are exactly the constants
used by C programs.

<P>
The Unix man page for <span class=manpage><i>getrlimit</i>(2)</span> lists the available
resources.  Note that not all systems use the same symbol or same
value to denote the same resource.

<P>
<dl><dt><b><a name="l2h-1512"><tt>RLIMIT_CORE</tt></a></b>
<dd>
  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
  image.
</dl>

<P>
<dl><dt><b><a name="l2h-1513"><tt>RLIMIT_CPU</tt></a></b>
<dd>
  The maximum amount of CPU time (in seconds) that a process can
  use. If this limit is exceeded, a <tt class=constant>SIGXCPU</tt> signal is sent to
  the process. (See the <tt class=module><a href="module-signal.html">signal</a></tt> module documentation for
  information about how to catch this signal and do something useful,
  e.g. flush open files to disk.)
</dl>

<P>
<dl><dt><b><a name="l2h-1514"><tt>RLIMIT_FSIZE</tt></a></b>
<dd>
  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.
</dl>

<P>
<dl><dt><b><a name="l2h-1515"><tt>RLIMIT_DATA</tt></a></b>
<dd>
  The maximum size (in bytes) of the process's heap.
</dl>

<P>
<dl><dt><b><a name="l2h-1516"><tt>RLIMIT_STACK</tt></a></b>
<dd>
  The maximum size (in bytes) of the call stack for the current
  process.
</dl>

<P>
<dl><dt><b><a name="l2h-1517"><tt>RLIMIT_RSS</tt></a></b>
<dd>
  The maximum resident set size that should be made available to the
  process.
</dl>

<P>
<dl><dt><b><a name="l2h-1518"><tt>RLIMIT_NPROC</tt></a></b>
<dd>
  The maximum number of processes the current process may create.
</dl>

<P>
<dl><dt><b><a name="l2h-1519"><tt>RLIMIT_NOFILE</tt></a></b>
<dd>
  The maximum number of open file descriptors for the current
  process.
</dl>

<P>
<dl><dt><b><a name="l2h-1520"><tt>RLIMIT_OFILE</tt></a></b>
<dd>
  The BSD name for <tt class=constant>RLIMIT_NOFILE</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-1521"><tt>RLIMIT_MEMLOC</tt></a></b>
<dd>
  The maximm address space which may be locked in memory.
</dl>

<P>
<dl><dt><b><a name="l2h-1522"><tt>RLIMIT_VMEM</tt></a></b>
<dd>
  The largest area of mapped memory which the process may occupy.
</dl>

<P>
<dl><dt><b><a name="l2h-1523"><tt>RLIMIT_AS</tt></a></b>
<dd>
  The maximum area (in bytes) of address space which may be taken by
  the process.
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="node168.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-resource.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-resource.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="node168.html">8.11.2 Resource Usage</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-resource.html">8.11 resource  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-resource.html">8.11 resource  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
