1 .\" $NetBSD: getrlimit.2,v 1.36 2012/06/09 02:36:25 christos Exp $
3 .\" Copyright (c) 1980, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93
38 .Nd control maximum system resource consumption
44 .Fn getrlimit "int resource" "struct rlimit *rlp"
46 .Fn setrlimit "int resource" "const struct rlimit *rlp"
48 Limits on the consumption of system resources by the current process
49 and each process it creates may be obtained with the
51 call, and set with the
54 Resources of an arbitrary process can be obtained/changed using
59 parameter is one of the following:
60 .Bl -tag -width RLIMIT_FSIZEAA
62 The maximum amount (in bytes) of virtual memory the process is allowed to map.
64 The largest size (in bytes)
66 file that may be created.
68 The maximum amount of CPU time (in seconds) to be used by
71 The maximum size (in bytes) of the data segment for a process;
72 this defines how far a program may extend its break with the
76 The largest size (in bytes) file that may be created.
78 The maximum size (in bytes) which a process may lock into memory
83 The maximum number of open files for this process.
85 The maximum number of simultaneous processes for this user id.
87 The maximum number of simultaneous threads (Lightweight Processes) for this
89 Kernel threads and the first thread of each process are not counted against
92 The maximum size (in bytes) to which a process's resident set size may
94 This imposes a limit on the amount of physical memory to be given to
95 a process; if memory is tight, the system will prefer to take memory
96 from processes that are exceeding their declared resident set size.
98 The maximum size (in bytes) of the socket buffers
106 The maximum size (in bytes) of the stack segment for a process;
107 this defines how far a program's stack segment may be extended.
108 Stack extension is performed automatically by the system.
111 A resource limit is specified as a soft limit and a hard limit.
112 When a soft limit is exceeded a process may receive a signal (for example,
113 if the CPU time or file size is exceeded), but it will be allowed to
114 continue execution until it reaches the hard limit (or modifies
118 structure is used to specify the hard and soft limits on a resource,
119 .Bd -literal -offset indent
121 rlim_t rlim_cur; /* current (soft) limit */
122 rlim_t rlim_max; /* hard limit */
126 Only the super-user may raise the maximum limits.
127 Other users may only alter
129 within the range from 0 to
131 or (irreversibly) lower
136 value for a limit is defined as
139 Because this information is stored in the per-process information,
140 this system call must be executed directly by the shell if it
141 is to affect all future processes created by the shell.
142 Thus, shells provide built-in commands to change the limits
151 The system refuses to extend the data or stack space when the limits
152 would be exceeded in the normal way: a
154 call fails if the data space limit is reached.
155 When the stack limit is reached, the process receives
158 if this signal is not
159 caught by a handler using the signal stack, this signal
160 will kill the process.
162 A file I/O operation that would create a file larger that the process'
163 soft limit will cause the write to fail and a signal
166 generated; this normally terminates the process, but may be caught.
167 When the soft CPU time limit is exceeded, a signal
172 A 0 return value indicates that the call succeeded, changing
173 or returning the resource limit.
174 Otherwise, \-1 is returned and the global variable
176 is set to indicate the error.
185 The address specified for
191 was invalid; or, in the
195 exceeds the specified
198 The limit specified to
201 raised the maximum limit value, and the caller is not the super-user.
206 function may fail if:
209 The limit specified to
211 cannot be lowered, because current usage is already higher than the limit.
223 .\" With exception of
225 .\" (which is not currently supported), the
229 .\" functions conform to
234 function call appeared in
239 is not implemented in
241 which means that process memory size limits are not enforced.