ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/setrlim.htm

255 lines
6.6 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>setrlimit()--Set resource limit</title>
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Begin Header Records ========================================== -->
<!-- Edited by Kersten Jan 02 -->
<!-- This file has undergone html cleanup July 2002 by JET -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<a name="Top_Of_Page"></a>
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<h2>setrlimit()--Set resource limit</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax
<pre>
#include &lt;sys/resource.h&gt;
int setrlimit(int <em>resource</em>, const struct rlimit *<em>rlp</em>);
</pre>
&nbsp;&nbsp;Service Program Name: QP0WSRV1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>setrlimit()</strong> function sets the resource limit for the
specified <em>resource</em>. A resource limit is a way for the operating system
to enforce a limit on a variety of resources used by a process. A resource
limit is represented by a rlimit structure. The rlim_cur member specifies the
current or soft limit and the rlim_max member specifies the maximum or hard
limit.</p>
<p>A soft limit can be changed to any value that is less than or equal to the
hard limit. The hard limit can be changed to any value that is greater than or
equal to the soft limit. Only a process with appropriate authorities can
increase a hard limit.</p>
<p>The <strong>setrlimit()</strong> function supports the following
resources:</p>
<table cellpadding="5">
<!-- cols="15 85" -->
<tr>
<td align="left" valign="top"><em>RLIMIT_FSIZE (0)</em></td>
<td align="left" valign="top">The maximum size of a file in bytes that can be
created by a process.</td>
</tr>
</table>
<p>The <strong>setrlimit()</strong> function does not support setting the
following resources: RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA,
RLIMIT_NOFILE, and RLIMIT_STACK. The <strong>setrlimit()</strong> function
returns -1 and sets errno to ENOTSUP when called with one of these
resources.</p>
<p>The value of RLIM_INFINITY is considered to be larger than any other limit
value. If the value of the limit is set to RLIM_INFINITY, then a limit is not
enforced for that resource. If the value of the limit is set to RLIM_SAVED_MAX,
the new limit is the corresponding saved hard limit. If the value of the limit
is RLIM_SAVED_CUR, the new limit is the corresponding saved soft limit.</p>
<h3>Parameters</h3>
<dl>
<dt><strong><em>resource</em></strong></dt>
<dd>(Input)
<p>The resource to set the limits for.</p>
</dd>
<dt><strong>*<em>rlp</em></strong></dt>
<dd>(Input)
<p>Pointer to a struct rlim_t that contains the new values for the hard and
soft limits.</p>
</dd>
</dl>
<br>
<h3>Authorities and Locks</h3>
<p>The current user profile must have *JOBCTL special authority to increase the
hard limit.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="5 95" -->
<tr>
<td align="left" valign="top"><strong>0</strong></td>
<td align="left" valign="top"><strong>setrlimit()</strong> was successful.</td>
</tr>
<tr>
<td align="left" valign="top"><strong>-1</strong></td>
<td align="left" valign="top"><strong>setrlimit()</strong> was not successful.
The <em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>setrlimit()</strong> is not successful, <em>errno</em> usually
indicates one of the following errors. Under some conditions, <em>errno</em>
could indicate an error other than those listed here.</p>
<dl>
<dt><em>[EFAULT]</em></dt>
<dd>
<p>The address used for an argument is not correct.</p>
<p>In attempting to use an argument in a call, the system detected an address
that is not valid.</p>
<p>While attempting to access a parameter passed to this function, the system
detected an address that is not valid.</p>
</dd>
<dt><em>[EINVAL]</em></dt>
<dd>
<p>An invalid parameter was found.</p>
<p>An invalid <em>resource</em> was specified.</p>
<p>The new soft limit is greater the new hard limit.</p>
<p>The new hard limit is lower than the new soft limit.</p>
</dd>
<dt><em>[EPERM]</em></dt>
<dd>
<p>Permission denied.</p>
<p>An attempt was made to increase the hard limit and the current user profile
does not have *JOBCTL special authority.</p>
</dd>
<dt><em>[ENOTSUP]</em></dt>
<dd>
<p>Operation not supported.</p>
<p>The operation, though supported in general, is not supported for the
requested <em>resource</em>.</p>
</dd>
</dl>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>sys/resource.h</strong>&gt; file (see <a href="unix13.htm">
Header Files for UNIX-Type Functions</a>)<br>
<br>
</li>
<li><a href="getrlim.htm">getrlimit()</a>--Get resource limit<br>
<br>
</li>
<li><a href="ulimit.htm">ulimit()</a>--Get and set process limits<br>
<br>
</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<pre>
#include &lt;sys/resource.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;errno.h&gt;
int main (int argc, char *argv[])
{
struct rlimit limit;
/* Set the file size resource limit. */
limit.rlim_cur = 65535;
limit.rlim_max = 65535;
if (setrlimit(RLIMIT_FSIZE, &amp;limit) != 0) {
printf("setrlimit() failed with errno=%d\n", errno);
exit(1);
}
/* Get the file size resource limit. */
if (getrlimit(RLIMIT_FSIZE, &amp;limit) != 0) {
printf("getrlimit() failed with errno=%d\n", errno);
exit(1);
}
printf("The soft limit is %llu\n", limit.rlim_cur);
printf("The hard limit is %llu\n", limit.rlim_max);
exit(0);
}
</pre>
<strong>Example Output:</strong>
<pre>
The soft limit is 65535
The hard limit is 65535
</pre>
<br>
<br>
<hr>
Introduced: V5R2
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>