Skip to content

Instantly share code, notes, and snippets.

@teeler
Created September 14, 2018 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teeler/896e3eee30c36a5f62db20a67bb62915 to your computer and use it in GitHub Desktop.
Save teeler/896e3eee30c36a5f62db20a67bb62915 to your computer and use it in GitHub Desktop.
<!-- Creator : groff version 1.19.2 -->
<!-- CreationDate: Fri Sep 14 10:51:19 2018 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; }
pre { margin-top: 0; margin-bottom: 0; }
table { margin-top: 0; margin-bottom: 0; }
</style>
<title></title>
</head>
<body>
<hr>
<p valign="top">GETRLIMIT(2) BSD System Calls Manual
GETRLIMIT(2)</p>
<p style="margin-top: 1em" valign="top"><b>NAME</b></p>
<p style="margin-left:8%;"><b>getrlimit</b>,
<b>setrlimit</b> &mdash; control maximum system resource
consumption</p>
<p style="margin-top: 1em" valign="top"><b>SYNOPSIS</b></p>
<p style="margin-left:8%;"><b>#include
&lt;sys/resource.h&gt;</b></p>
<p style="margin-left:8%; margin-top: 1em"><i>int</i></p>
<p valign="top"><b>getrlimit</b>(<i>int&nbsp;resource</i>,
<i>struct&nbsp;rlimit&nbsp;*rlp</i>);</p>
<p style="margin-left:8%; margin-top: 1em"><i>int</i></p>
<p valign="top"><b>setrlimit</b>(<i>int&nbsp;resource</i>,
<i>const&nbsp;struct&nbsp;rlimit&nbsp;*rlp</i>);</p>
<p style="margin-top: 1em" valign="top"><b>DESCRIPTION</b></p>
<p style="margin-left:8%;">Limits on the consumption of
system resources by the current process and each process it
creates may be obtained with the <b>getrlimit</b>() call,
and set with the <b>setrlimit</b>() call.</p>
<p style="margin-left:8%; margin-top: 1em">The
<i>resource</i> parameter is one of the following:</p>
<p style="margin-top: 1em" valign="top">RLIMIT_CORE</p>
<p style="margin-left:32%; margin-top: 1em">The largest
size (in bytes) core file that may be created.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_CPU</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
amount of cpu time (in seconds) to be used by each
process.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_DATA</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
size (in bytes) of the data segment for a process; this
defines how far a program may extend its break with the
sbrk(2) system call.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_FSIZE</p>
<p style="margin-left:32%; margin-top: 1em">The largest
size (in bytes) file that may be created.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_MEMLOCK</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
size (in bytes) which a process may lock into memory using
the mlock(2) function.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_NOFILE</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
number of open files for this process.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_NPROC</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
number of simultaneous processes for this user id.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_RSS</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
size (in bytes) to which a process&rsquo;s resident set size
may grow. This imposes a limit on the amount of physical
memory to be given to a process; if memory is tight, the
system will prefer to take memory from processes that are
exceeding their declared resident set size.</p>
<p style="margin-top: 1em" valign="top">RLIMIT_STACK</p>
<p style="margin-left:32%; margin-top: 1em">The maximum
size (in bytes) of the stack segment for a process; this
defines how far a program&rsquo;s stack segment may be
extended. Stack extension is performed automatically by the
system.</p>
<p style="margin-left:8%; margin-top: 1em">A resource limit
is specified as a soft limit and a hard limit. When a soft
limit is exceeded a process may receive a signal (for
example, if the cpu time or file size is exceeded), but it
will be allowed to continue execution until it reaches the
hard limit (or modifies its resource limit). The
<i>rlimit</i> structure is used to specify the hard and soft
limits on a resource,</p>
<p style="margin-left:17%; margin-top: 1em">struct rlimit
{</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="29%"></td>
<td width="13%">
<p valign="top">rlim_t</p></td>
<td width="12%">
<p valign="top">rlim_cur;</p></td>
<td width="12%"></td>
<td width="12%">
<p valign="top">/* current (soft) limit */</p></td>
<td width="22%">
</td>
<tr valign="top" align="left">
<td width="29%"></td>
<td width="13%">
<p valign="top">rlim_t</p></td>
<td width="12%">
<p valign="top">rlim_max;</p></td>
<td width="12%"></td>
<td width="12%">
<p valign="top">/* hard limit */</p></td>
<td width="22%">
</td>
</table>
<p style="margin-left:17%;">};</p>
<p style="margin-left:8%; margin-top: 1em">Only the
super-user may raise the maximum limits. Other users may
only alter <i>rlim_cur</i> within the range from 0 to
<i>rlim_max</i> or (irreversibly) lower <i>rlim_max</i>.</p>
<p style="margin-left:8%; margin-top: 1em">Because this
information is stored in the per-process information, this
system call must be executed directly by the shell if it is
to affect all future processes created by the shell;
<b>limit</b> is thus a built-in command to csh(1) and
<b>ulimit</b> is the sh(1) equivalent.</p>
<p style="margin-left:8%; margin-top: 1em">The system
refuses to extend the data or stack space when the limits
would be exceeded in the normal way: a break call fails if
the data space limit is reached. When the stack limit is
reached, the process receives a segmentation fault
(SIGSEGV); if this signal is not caught by a handler using
the signal stack, this signal will kill the process.</p>
<p style="margin-left:8%; margin-top: 1em">A file I/O
operation that would create a file larger that the
process&rsquo; soft limit will cause the write to fail and a
signal SIGXFSZ to be generated; this normally terminates the
process, but may be caught. When the soft cpu time limit is
exceeded, a signal SIGXCPU is sent to the offending
process.</p>
<p style="margin-top: 1em" valign="top"><b>RETURN
VALUES</b></p>
<p style="margin-left:8%;">A 0 return value indicates that
the call succeeded, changing or returning the resource
limit. A return value of -1 indicates that an error
occurred, and an error code is stored in the global location
<i>errno</i>.</p>
<p style="margin-top: 1em" valign="top"><b>ERRORS</b></p>
<p style="margin-left:8%;">The <b>getrlimit</b>() and
<b>setrlimit</b>() system calls will fail if:</p>
<p style="margin-top: 1em" valign="top">[EFAULT]</p>
<p style="margin-left:37%; margin-top: 1em">The address
specified for <i>rlp</i> is invalid.</p>
<p style="margin-top: 1em" valign="top">[EINVAL]</p>
<p style="margin-left:37%; margin-top: 1em"><i>resource</i>
is invalid.</p>
<p style="margin-left:8%; margin-top: 1em">The
<b>setrlimit</b>() call will fail if:</p>
<p style="margin-top: 1em" valign="top">[EINVAL]</p>
<p style="margin-left:37%; margin-top: 1em">The specified
limit is invalid (e.g., RLIM_INFINITY or lower than
rlim_cur).</p>
<p style="margin-top: 1em" valign="top">[EPERM]</p>
<p style="margin-left:37%; margin-top: 1em">The limit
specified would have raised the maximum limit value and the
caller is not the super-user.</p>
<p style="margin-top: 1em" valign="top"><b>LEGACY
SYNOPSIS</b></p>
<p style="margin-left:8%;"><b>#include &lt;sys/types.h&gt;
<br>
#include &lt;sys/time.h&gt; <br>
#include &lt;sys/resource.h&gt;</b></p>
<p style="margin-left:8%; margin-top: 1em">The include
files &lt;<i>sys/types.h</i>&gt; and
&lt;<i>sys/time.h</i>&gt; are necessary.</p>
<p style="margin-top: 1em" valign="top"><b>COMPATIBILITY</b></p>
<p style="margin-left:8%;"><b>setrlimit</b>() now returns
with <i>errno</i> set to EINVAL in places that historically
succeeded. It no longer accepts &quot;rlim_cur =
RLIM_INFINITY&quot; for RLIM_NOFILE. Use &quot;rlim_cur =
min(OPEN_MAX, rlim_max)&quot;.</p>
<p style="margin-top: 1em" valign="top"><b>SEE ALSO</b></p>
<p style="margin-left:8%;">csh(1), sh(1), quota(2),
sigaction(2), sigaltstack(2), sysctl(3), compat(5)</p>
<p style="margin-top: 1em" valign="top"><b>HISTORY</b></p>
<p style="margin-left:8%;">The <b>getrlimit</b>() function
call appeared in 4.2BSD.</p>
<p style="margin-left:8%; margin-top: 1em">4th&nbsp;Berkeley
Distribution June&nbsp;4, 1993 4th&nbsp;Berkeley
Distribution</p>
<hr>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment