1 .\" $NetBSD: getrlimit.2,v 1.8 1995/10/12 15:40:58 jtc 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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93
42 .Nd control maximum system resource consumption
44 .Fd #include <sys/resource.h>
48 .Fa "struct rlimit *rlp"
53 .Fa "const struct rlimit *rlp"
56 Limits on the consumption of system resources by the current process
57 and each process it creates may be obtained with the
59 call, and set with the
65 parameter is one of the following:
66 .Bl -tag -width RLIMIT_FSIZEAA
69 The largest size (in bytes)
71 file that may be created.
74 The maximum amount of cpu time (in seconds) to be used by
78 The maximum size (in bytes) of the data segment for a process;
79 this defines how far a program may extend its break with the
84 The largest size (in bytes) file that may be created.
87 The maximum size (in bytes) which a process may lock into memory
93 The maximum number of open files for this process.
96 The maximum number of simultaneous processes for this user id.
99 The maximum size (in bytes)
100 to which a process's resident set size may grow.
101 This imposes a limit on the amount of physical memory
102 to be given to a process;
103 if memory is tight, the system will prefer to take memory
104 from processes that are exceeding their declared resident set size.
107 The maximum size (in bytes) of the stack segment for a process;
108 this defines how far a program's stack segment may be extended.
109 Stack extension is performed automatically by the system.
112 A resource limit is specified as a soft limit and a hard limit. When a
113 soft limit is exceeded a process may receive a signal (for example, if
114 the cpu time or file size is exceeded), but it will be allowed to
115 continue execution until it reaches the hard limit (or modifies
116 its resource limit). The
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. Other users
129 within the range from 0 to
131 or (irreversibly) lower
134 Because this information is stored in the per-process information,
135 this system call must be executed directly by the shell if it
136 is to affect all future processes created by the shell;
138 is thus a built-in command to
146 The system refuses to extend the data or stack space when the limits
147 would be exceeded in the normal way: a
149 call fails if the data space limit is reached.
150 When the stack limit is reached, the process receives
153 if this signal is not
154 caught by a handler using the signal stack, this signal
155 will kill the process.
157 A file I/O operation that would create a file larger that the process'
158 soft limit will cause the write to fail and a signal
161 generated; this normally terminates the process, but may be caught. When
162 the soft cpu time limit is exceeded, a signal
167 A 0 return value indicates that the call succeeded, changing
168 or returning the resource limit. A return value of -1 indicates
169 that an error occurred, and an error code is stored in the global
177 system calls will fail if:
181 The address specified for
196 The specified limit is invalid
197 (e.g., RLIM_INFINITY or lower than rlim_cur).
200 The limit specified would have raised the maximum limit value
201 and the caller is not the super-user.
204 .Fd #include <sys/types.h>
205 .Fd #include <sys/time.h>
206 .Fd #include <sys/resource.h>
217 set to EINVAL in places that historically succeeded.
218 It no longer accepts "rlim_cur = RLIM_INFINITY" for RLIM_NOFILE.
219 Use "rlim_cur = min(OPEN_MAX, rlim_max)".
231 function call appeared in