Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/getrlimit.html
2024-02-19 00:21:47 -05:00

225 lines
10 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>getrlimit</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="getrlimit"></a> <a name="tag_03_246"></a><!-- getrlimit -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_246_01"></a>NAME</h4>
<blockquote>getrlimit, setrlimit - control maximum resource consumption</blockquote>
<h4><a name="tag_03_246_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include &lt;<a href="../basedefs/sys/resource.h.html">sys/resource.h</a>&gt;<br>
<br>
int getrlimit(int</tt> <i>resource</i><tt>, struct rlimit *</tt><i>rlp</i><tt>);<br>
int setrlimit(int</tt> <i>resource</i><tt>, const struct rlimit *</tt><i>rlp</i><tt>); <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_246_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>getrlimit</i>() function shall get, and the <i>setrlimit</i>() function shall set, limits on the consumption of a variety
of resources.</p>
<p>Each call to either <i>getrlimit</i>() or <i>setrlimit</i>() identifies a specific resource to be operated upon as well as a
resource limit. A resource limit is represented by an <b>rlimit</b> structure. The <i>rlim_cur</i> member specifies the current or
soft limit and the <i>rlim_max</i> member specifies the maximum or 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. Only a process with appropriate privileges can raise a hard limit. Both hard and soft limits can be
changed in a single call to <i>setrlimit</i>() subject to the constraints described above.</p>
<p>The value RLIM_INFINITY, defined in <a href="../basedefs/sys/resource.h.html"><i>&lt;sys/resource.h&gt;</i></a>, shall be
considered to be larger than any other limit value. If a call to <i>getrlimit</i>() returns RLIM_INFINITY for a resource, it means
the implementation shall not enforce limits on that resource. Specifying RLIM_INFINITY as any resource limit value on a successful
call to <i>setrlimit</i>() shall inhibit enforcement of that resource limit.</p>
<p>The following resources are defined:</p>
<dl compact>
<dt>RLIMIT_CORE</dt>
<dd>This is the maximum size of a <b>core</b> file, in bytes, that may be created by a process. A limit of 0 shall prevent the
creation of a <b>core</b> file. If this limit is exceeded, the writing of a <b>core</b> file shall terminate at this size.</dd>
<dt>RLIMIT_CPU</dt>
<dd>This is the maximum amount of CPU time, in seconds, used by a process. If this limit is exceeded, SIGXCPU shall be generated
for the process. If the process is catching or ignoring SIGXCPU, or all threads belonging to that process are blocking SIGXCPU, the
behavior is unspecified.</dd>
<dt>RLIMIT_DATA</dt>
<dd>This is the maximum size of a process' data segment, in bytes. If this limit is exceeded, the <a href=
"../functions/malloc.html"><i>malloc</i>()</a> function shall fail with <i>errno</i> set to [ENOMEM].</dd>
<dt>RLIMIT_FSIZE</dt>
<dd>This is the maximum size of a file, in bytes, that may be created by a process. If a write or truncate operation would cause
this limit to be exceeded, SIGXFSZ shall be generated for the thread. If the thread is blocking, or the process is catching or
ignoring SIGXFSZ, continued attempts to increase the size of a file from end-of-file to beyond the limit shall fail with
<i>errno</i> set to [EFBIG].</dd>
<dt>RLIMIT_NOFILE</dt>
<dd>This is a number one greater than the maximum value that the system may assign to a newly-created descriptor. If this limit is
exceeded, functions that allocate new file descriptors may fail with <i>errno</i> set to [EMFILE]. This limit constrains the number
of file descriptors that a process may allocate.</dd>
<dt>RLIMIT_STACK</dt>
<dd>This is the maximum size of a process' stack, in bytes. The implementation does not automatically grow the stack beyond this
limit. If this limit is exceeded, SIGSEGV shall be generated for the thread. If the thread is blocking SIGSEGV, or the process is
ignoring or catching SIGSEGV and has not made arrangements to use an alternate stack, the disposition of SIGSEGV shall be set to
SIG_DFL before it is generated.</dd>
<dt>RLIMIT_AS</dt>
<dd>This is the maximum size of a process' total available memory, in bytes. If this limit is exceeded, the <a href=
"../functions/malloc.html"><i>malloc</i>()</a> and <a href="../functions/mmap.html"><i>mmap</i>()</a> functions shall fail with
<i>errno</i> set to [ENOMEM]. In addition, the automatic stack growth fails with the effects outlined above.</dd>
</dl>
<p>When using the <i>getrlimit</i>() function, if a resource limit can be represented correctly in an object of type <b>rlim_t</b>,
then its representation is returned; otherwise, if the value of the resource limit is equal to that of the corresponding saved hard
limit, the value returned shall be RLIM_SAVED_MAX; otherwise, the value returned shall be RLIM_SAVED_CUR.</p>
<p>When using the <i>setrlimit</i>() function, if the requested new limit is RLIM_INFINITY, the new limit shall be &quot;no limit'';
otherwise, if the requested new limit is RLIM_SAVED_MAX, the new limit shall be the corresponding saved hard limit; otherwise, if
the requested new limit is RLIM_SAVED_CUR, the new limit shall be the corresponding saved soft limit; otherwise, the new limit
shall be the requested value. In addition, if the corresponding saved limit can be represented correctly in an object of type
<b>rlim_t</b> then it shall be overwritten with the new limit.</p>
<p>The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is unspecified unless a previous call to <i>getrlimit</i>()
returned that value as the soft or hard limit for the corresponding resource limit.</p>
<p>The determination of whether a limit can be correctly represented in an object of type <b>rlim_t</b> is implementation-defined.
For example, some implementations permit a limit whose value is greater than RLIM_INFINITY and others do not.</p>
<p>The <i><a href="../functions/exec.html">exec</a></i> family of functions shall cause resource limits to be saved.</p>
</blockquote>
<h4><a name="tag_03_246_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>getrlimit</i>() and <i>setrlimit</i>() shall return 0. Otherwise, these functions shall return -1
and set <i>errno</i> to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_246_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>getrlimit</i>() and <i>setrlimit</i>() functions shall fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd>An invalid <i>resource</i> was specified; or in a <i>setrlimit</i>() call, the new <i>rlim_cur</i> exceeds the new
<i>rlim_max</i>.</dd>
<dt>[EPERM]</dt>
<dd>The limit specified to <i>setrlimit</i>() would have raised the maximum limit value, and the calling process does not have
appropriate privileges.</dd>
</dl>
<p>The <i>setrlimit</i>() function may fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd>The limit specified cannot be lowered because current usage is already higher than the limit.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_246_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_246_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>If a process attempts to set the hard limit or soft limit for RLIMIT_NOFILE to less than the value of {_POSIX_OPEN_MAX} from <a
href="../basedefs/limits.h.html"><i>&lt;limits.h&gt;</i></a>, unexpected behavior may occur.</p>
</blockquote>
<h4><a name="tag_03_246_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_246_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_246_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a> , <a href="fork.html"><i>fork</i>()</a> , <a href=
"malloc.html"><i>malloc</i>()</a> , <a href="open.html"><i>open</i>()</a> , <a href="sigaltstack.html"><i>sigaltstack</i>()</a> ,
<a href="sysconf.html"><i>sysconf</i>()</a> , <a href="ulimit.html"><i>ulimit</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/stropts.h.html"><i>&lt;stropts.h&gt;</i></a>, <a href=
"../basedefs/sys/resource.h.html"><i>&lt;sys/resource.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_246_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_246_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
<p>An APPLICATION USAGE section is added.</p>
<p>Large File Summit extensions are added.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>