236 lines
6.0 KiB
HTML
236 lines
6.0 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>ulimit()--Get and set process limits</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 -->
|
||
|
<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>ulimit()--Get and set process limits</h2>
|
||
|
|
||
|
<div class="box" style="width: 50%;">
|
||
|
<br>
|
||
|
Syntax
|
||
|
|
||
|
<pre>
|
||
|
#include <ulimit.h>
|
||
|
|
||
|
long int ulimit(int <em>cmd</em>, ...);
|
||
|
</pre>
|
||
|
|
||
|
Service Program Name: QP0WSRV1<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<p>The <strong>ulimit()</strong> function provides a way to get and set process
|
||
|
resource limits. 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 has a
|
||
|
current or soft limit and a maximum or hard limit.</p>
|
||
|
|
||
|
<p>The <strong>ulimit()</strong> function is provided for compatibility with
|
||
|
older applications. The <a href="getrlim.htm">getrlimit()</a> and <a href=
|
||
|
"setrlim.htm">setrlimit()</a> functions should be used for working with
|
||
|
resource limits.</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>ulimit()</strong> function supports the following <em>cmd</em>
|
||
|
values:</p>
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<!-- cols="15 85" -->
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>UL_GETFSIZE (0)</em></td>
|
||
|
<td align="left" valign="top">Return the current or soft limit for the file
|
||
|
size resource limit. The returned limit is in 512-byte blocks. The return value
|
||
|
is the integer part of the file size resource limit divided by 512.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top" nowrap><em>UL_SETFSIZE (1)</em></td>
|
||
|
<td align="left" valign="top">Set the current or soft limit and the maximum or
|
||
|
hard limit for the file size resource limit. The second argument is taken as a
|
||
|
long int that represents the limit in 512-byte blocks. The specified value is
|
||
|
multiplied by 512 to set the resource limit. If the result overflows an rlim_t,
|
||
|
<strong>ulimit()</strong> returns -1 and sets <em>errno</em> to EINVAL. The new
|
||
|
file size resource limit is returned.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
<h3>Parameters</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong><em>cmd</em></strong></dt>
|
||
|
|
||
|
<dd>(Input)
|
||
|
|
||
|
<p>The command to be performed.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>...</strong></dt>
|
||
|
|
||
|
<dd>(Input)
|
||
|
|
||
|
<p>When the <em>cmd</em> is UL_SETFSIZE, a long int that represents the limit
|
||
|
in 512-byte blocks.</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="10 90" -->
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><strong>value</strong></td>
|
||
|
<td align="left" valign="top"><strong>ulimit()</strong> was successful. The
|
||
|
value is the requested limit.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><strong>-1</strong></td>
|
||
|
<td align="left" valign="top"><strong>ulimit()</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>ulimit()</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>[EINVAL]</em></dt>
|
||
|
<dd><p>An invalid parameter was found. </p>
|
||
|
|
||
|
<p>An invalid <em>cmd</em> was specified.</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>
|
||
|
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
<h3>Related Information</h3>
|
||
|
|
||
|
<ul>
|
||
|
<li>The <<strong>ulimit.h</strong>> 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="setrlim.htm">setrlimit()</a>--Set resource limit<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 <ulimit.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <errno.h>
|
||
|
|
||
|
int main (int argc, char *argv[])
|
||
|
{
|
||
|
long int value;
|
||
|
long int limit;
|
||
|
|
||
|
/* Set the file size resource limit. */
|
||
|
limit = 65535;
|
||
|
errno = 0;
|
||
|
value = ulimit(UL_SETFSIZE, limit);
|
||
|
if ((value == -1) && (errno != 0)) {
|
||
|
printf("ulimit() failed with errno=%d\n", errno);
|
||
|
exit(1);
|
||
|
}
|
||
|
printf("The limit is set to %ld\n", value);
|
||
|
|
||
|
/* Get the file size resource limit. */
|
||
|
value = ulimit(UL_GETFSIZE);
|
||
|
if ((value == -1) && (errno != 0)) {
|
||
|
printf("ulimit() failed with errno=%d\n", errno);
|
||
|
exit(1);
|
||
|
}
|
||
|
printf("The limit is %ld\n", value);
|
||
|
|
||
|
exit(0);
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
<strong>Example Output:</strong>
|
||
|
|
||
|
<pre>
|
||
|
The limit is set to 65535
|
||
|
The 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>
|
||
|
|