]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getrlimit.2
Change things like "NULL-terminated string" to "null-terminated string"
[thirdparty/man-pages.git] / man2 / getrlimit.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
4 .\" Copyright (c) 2002 Michael Kerrisk
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1996-01-13 by Arnt Gulbrandsen <agulbra@troll.no>
29 .\" Modified 1996-01-22 by aeb, following a remark by
30 .\" Tigran Aivazian <tigran@sco.com>
31 .\" Modified 1996-04-14 by aeb, following a remark by
32 .\" Robert Bihlmeyer <robbe@orcus.ping.at>
33 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
34 .\" Modified 2001-05-04 by aeb, following a remark by
35 .\" HÃ¥vard Lygre <hklygre@online.no>
36 .\" Modified 2001-04-17 by Michael Kerrisk <mtk-manpages@gmx.net>
37 .\" Modified 2002-06-13 by Michael Kerrisk <mtk-manpages@gmx.net>
38 .\" Added note on non-standard behaviour when SIGCHLD is ignored.
39 .\" Modified 2002-07-09 by Michael Kerrisk <mtk-manpages@gmx.net>
40 .\" Enhanced descriptions of 'resource' values for [gs]etrlimit()
41 .\" Modified 2003-11-28 by aeb, added RLIMIT_CORE
42 .\" Modified 2004-03-26 by aeb, added RLIMIT_AS
43 .\" Modified 2004-06-16 by Michael Kerrisk <mtk-manpages@gmx.net>
44 .\" Added notes on CAP_SYS_RESOURCE
45 .\"
46 .\" 2004-11-16 -- mtk: the getrlimit.2 page, which formally included
47 .\" coverage of getrusage(2), has been split, so that the latter
48 .\" is now covered in its own getrusage.2.
49 .\"
50 .\" Modified 2004-11-16, mtk: A few other minor changes
51 .\" Modified 2004-11-23, mtk
52 .\" Added notes on RLIMIT_MEMLOCK, RLIMIT_NPROC, and RLIMIT_RSS
53 .\" to "CONFORMING TO"
54 .\" Modified 2004-11-25, mtk
55 .\" Rewrote discussion on RLIMIT_MEMLOCK to incorporate kernel
56 .\" 2.6.9 changes.
57 .\" Added note on RLIMIT_CPU error in older kernels
58 .\" 2004-11-03, mtk, Added RLIMIT_SIGPENDING
59 .\" 2005-07-13, mtk, documented RLIMIT_MSGQUEUE limit.
60 .\" 2005-07-28, mtk, Added descriptions of RLIMIT_NICE and RLIMIT_RTPRIO
61 .\"
62 .TH GETRLIMIT 2 2005-09-20 "Linux 2.6.13" "Linux Programmer's Manual"
63 .SH NAME
64 getrlimit, setrlimit \- get/set resource limits
65 .SH SYNOPSIS
66 .B #include <sys/time.h>
67 .br
68 .B #include <sys/resource.h>
69 .sp
70 .BI "int getrlimit(int " resource ", struct rlimit *" rlim );
71 .br
72 .BI "int setrlimit(int " resource ", const struct rlimit *" rlim );
73 .SH DESCRIPTION
74 .BR getrlimit ()
75 and
76 .BR setrlimit ()
77 get and set resource limits respectively.
78 Each resource has an associated soft and hard limit, as defined by the
79 .B rlimit
80 structure (the
81 .I rlim
82 argument to both
83 .BR getrlimit ()
84 and
85 .BR setrlimit ()):
86 .PP
87 .in +0.5i
88 .nf
89 struct rlimit {
90 rlim_t rlim_cur; /* Soft limit */
91 rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */
92 };
93
94 .fi
95 .in -0.5i
96 The soft limit is the value that the kernel enforces for the
97 corresponding resource.
98 The hard limit acts as a ceiling for the soft limit:
99 an unprivileged process may only set its soft limit to a value in the
100 range from 0 up to the hard limit, and (irreversibly) lower its hard limit.
101 A privileged process (under Linux: one with the
102 .B CAP_SYS_RESOURCE
103 capability) may make arbitrary changes to either limit value.
104 .PP
105 The value
106 .B RLIM_INFINITY
107 denotes no limit on a resource (both in the structure returned by
108 .BR getrlimit ()
109 and in the structure passed to
110 .BR setrlimit ()).
111 .PP
112 .I resource
113 must be one of:
114 .TP
115 .B RLIMIT_AS
116 The maximum size of the process's virtual memory (address space) in bytes.
117 .\" since 2.0.27 / 2.1.12
118 This limit affects calls to
119 .BR brk (2),
120 .BR mmap (2)
121 and
122 .BR mremap (2),
123 which fail with the error
124 .B ENOMEM
125 upon exceeding this limit. Also automatic stack expansion will fail
126 (and generate a
127 .B SIGSEGV
128 that kills the process if no alternate stack
129 has been made available via
130 .BR sigaltstack (2)).
131 Since the value is a \fIlong\fP, on machines with a 32-bit \fIlong\fP
132 either this limit is at most 2 GiB, or this resource is unlimited.
133 .TP
134 .B RLIMIT_CORE
135 Maximum size of
136 .I core
137 file. When 0 no core dump files are created.
138 When non-zero, larger dumps are truncated to this size.
139 .TP
140 .B RLIMIT_CPU
141 CPU time limit in seconds.
142 When the process reaches the soft limit, it is sent a
143 .B SIGXCPU
144 signal.
145 The default action for this signal is to terminate the process.
146 However, the signal can be caught, and the handler can return control to
147 the main program.
148 If the process continues to consume CPU time, it will be sent
149 .B SIGXCPU
150 once per second until the hard limit is reached, at which time
151 it is sent
152 .BR SIGKILL .
153 (This latter point describes Linux 2.2 through 2.6 behaviour.
154 Implementations vary in how they treat processes which continue to
155 consume CPU time after reaching the soft limit.
156 Portable applications that need to catch this signal should
157 perform an orderly termination upon first receipt of
158 .BR SIGXCPU .)
159 .TP
160 .B RLIMIT_DATA
161 The maximum size of the process's data segment (initialized data,
162 uninitialized data, and heap).
163 This limit affects calls to
164 .BR brk ()
165 and
166 .BR sbrk (),
167 which fail with the error
168 .B ENOMEM
169 upon encountering the soft limit of this resource.
170 .TP
171 .B RLIMIT_FSIZE
172 The maximum size of files that the process may create.
173 Attempts to extend a file beyond this limit result in delivery of a
174 .B SIGXFSZ
175 signal.
176 By default, this signal terminates a process, but a process can
177 catch this signal instead, in which case the relevant system call (e.g.,
178 .BR write ()
179 .BR truncate ())
180 fails with the error
181 .BR EFBIG .
182 .TP
183 .BR RLIMIT_LOCKS " (Early Linux 2.4 only)"
184 .\" to be precise: Linux 2.4.0-test9; no longer in 2.4.25 / 2.5.65
185 A limit on the combined number of
186 .BR flock ()
187 locks and
188 .BR fcntl ()
189 leases that this process may establish.
190 .TP
191 .B RLIMIT_MEMLOCK
192 The maximum number of bytes of memory that may be locked
193 into RAM.
194 In effect this limit is rounded down to the nearest multiple
195 of the system page size.
196 This limit affects
197 .BR mlock (2)
198 and
199 .BR mlockall (2)
200 and the
201 .BR mmap (2)
202 .B MAP_LOCKED
203 operation.
204 Since Linux 2.6.9 it also affects the
205 .BR shmctl (2)
206 .B SHM_LOCK
207 operation, where it sets a maximum on the total bytes in
208 shared memory segments (see
209 .BR shmget (2))
210 that may be locked by the real user ID of the calling process.
211 The
212 .BR shmctl (2)
213 .B SHM_LOCK
214 locks are accounted for separately from the per-process memory
215 locks established by
216 .BR mlock (2),
217 .BR mlockall (2),
218 and
219 .BR mmap (2)
220 .BR MAP_LOCKED ;
221 a process can lock bytes up to this limit in each of these
222 two categories.
223 In Linux kernels before 2.6.9, this limit controlled the amount of
224 memory that could be locked by a privileged process.
225 Since Linux 2.6.9, no limits are placed on the amount of memory
226 that a privileged process may lock, and this limit instead governs
227 the amount of memory that an unprivileged process may lock.
228 .TP
229 .BR RLIMIT_MSGQUEUE " (Since Linux 2.6.8)"
230 Specifies the limit on the number of bytes that can be allocated
231 for POSIX message queues for the real user ID of the calling process.
232 This limit is enforced for
233 .BR mq_open (3).
234 .\" FIXME there is no mq_open.3 page yet
235 Each message queue that the user creates counts (until it is removed)
236 against this limit according to the formula:
237 .nf
238
239 bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
240 attr.mq_maxmsg * attr.mq_msgsize
241
242 .fi
243 where
244 .I attr
245 is the
246 .I mq_attr
247 structure specified as the fourth argument to
248 .BR mq_open ().
249
250 The first addend in the formula, which includes
251 .I "sizeof(struct msg_msg *)"
252 (4 bytes on Linux/x86), ensures that the user cannot
253 create an unlimited number of zero-length messages (such messages
254 nevertheless each consume some system memory for bookkeeping overhead).
255 .TP
256 .BR RLIMIT_NICE " (since kernel 2.6.12, but see BUGS below)"
257 Specifies a ceiling to which the process's nice value can be raised using
258 .BR setpriority (2)
259 or
260 .BR nice (2).
261 The actual ceiling for the nice value is calculated as
262 .IR "20\ \-\ rlim_cur" .
263 (This strangeness occurs because negative numbers cannot be specified
264 as resource limit values, since they typically have special meanings.
265 For example, RLIM_INFINITY typically is the same as \-1.)
266 .TP
267 .B RLIMIT_NOFILE
268 Specifies a value one greater than the maximum file descriptor number
269 that can be opened by this process.
270 Attempts
271 .RB ( open (),
272 .BR pipe (),
273 .BR dup (),
274 etc.)
275 to exceed this limit yield the error
276 .BR EMFILE .
277 .TP
278 .B RLIMIT_NPROC
279 The maximum number of processes that can be created for the real user
280 ID of the calling process.
281 Upon encountering this limit,
282 .BR fork ()
283 fails with the error
284 .BR EAGAIN .
285 .TP
286 .B RLIMIT_RSS
287 Specifies the limit (in pages) of the process's resident set
288 (the number of virtual pages resident in RAM).
289 This limit only has effect in Linux 2.4.x, x < 30, and there only
290 affects calls to
291 .BR madvise ()
292 specifying
293 .BR MADV_WILLNEED .
294 .\" As at kernel 2.6.12, this limit still does nothing in 2.6 though
295 .\" talk of making it do something has surfaced from time to time in LKML
296 .\" -- MTK, Jul 05
297 .TP
298 .BR RLIMIT_RTPRIO " (Since Linux 2.6.12, but see BUGS)"
299 Specifies a ceiling on the real-time priority that may be set for
300 this process using
301 .BR sched_setscheduler (2)
302 and
303 .BR sched_setparam (2).
304 .TP
305 .BR RLIMIT_SIGPENDING " (Since Linux 2.6.8)"
306 Specifies the limit on the number of signals
307 that may be queued for the real user ID of the calling process.
308 Both standard and real-time signals are counted for the purpose of
309 checking this limit.
310 However, the limit is only enforced for
311 .BR sigqueue (2);
312 it is always possible to use
313 .BR kill (2)
314 to queue one instance of any of the signals that are not already
315 queued to the process.
316 .\" This replaces the /proc/sys/kernel/rtsig-max system-wide limit
317 .\" that was present in kernels <= 2.6.7. MTK Dec 04
318 .TP
319 .B RLIMIT_STACK
320 The maximum size of the process stack, in bytes.
321 Upon reaching this limit, a
322 .B SIGSEGV
323 signal is generated.
324 To handle this signal, a process must employ an alternate signal stack
325 .RB ( sigaltstack (2)).
326 .PP
327 .B RLIMIT_OFILE
328 is the BSD name for
329 .BR RLIMIT_NOFILE .
330 .SH "RETURN VALUE"
331 On success, zero is returned. On error, \-1 is returned, and
332 .I errno
333 is set appropriately.
334 .SH ERRORS
335 .TP
336 .B EFAULT
337 .I rlim
338 points outside the accessible address space.
339 .TP
340 .B EINVAL
341 .I resource
342 is not valid;
343 or, for
344 .BR setrlimit ():
345 .IR rlim->rlim_cur
346 was greater than
347 .IR rlim->rlim_max .
348 .TP
349 .B EPERM
350 An unprivileged process tried to use \fBsetrlimit\fP() to
351 increase a soft or hard limit above the current hard limit; the
352 .B CAP_SYS_RESOURCE
353 capability is required to do this.
354 Or, the process tried to use \fBsetrlimit\fP() to increase
355 the soft or hard RLIMIT_NOFILE limit above the current kernel
356 maximum (NR_OPEN).
357 .SH BUGS
358 In older Linux kernels, the
359 .B SIGXCPU
360 and
361 .B SIGKILL
362 signals delivered when a process encountered the soft and hard
363 .B RLIMIT_CPU
364 limits were delivered one (CPU) second later than they should have been.
365 This was fixed in kernel 2.6.8.
366
367 A kernel bug means that
368 .B RLIMIT_RTPRIO
369 does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.
370
371 In kernel 2.6.12, there was an off-by-one mismatch
372 between the priority ranges returned by
373 .BR getpriority (2)
374 and
375 .BR RLIMIT_NICE .
376 This had the effect that actual ceiling for the nice value
377 was calculated as
378 .IR "19\ \-\ rlim_cur" .
379 This was fixed in kernel 2.6.13.
380 .\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=112256338703880&w=2
381
382 Kernels before 2.4.22 did not diagnose the error
383 .B EINVAL
384 for
385 .BR setrlimit ()
386 when
387 .IR rlim->rlim_cur
388 was greater than
389 .IR rlim->rlim_max .
390 .SH "CONFORMING TO"
391 SVr4, 4.3BSD.
392 .BR RLIMIT_MEMLOCK
393 and
394 .BR RLIMIT_NPROC
395 derive from BSD and are not specified in POSIX.1-2001;
396 they are present on the BSDs and Linux, but on few other implementations.
397 .BR RLIMIT_RSS
398 derives from BSD and is not specified in POSIX.1-2001;
399 it is nevertheless present on most implementations.
400 .BR RLIMIT_MSGQUEUE ,
401 .BR RLIMIT_NICE ,
402 .BR RLIMIT_RTPRIO ,
403 and
404 .B RLIMIT_SIGPENDING
405 are Linux specific.
406 .SH "SEE ALSO"
407 .BR dup (2),
408 .BR fcntl (2),
409 .BR fork (2),
410 .BR getrusage (2),
411 .BR mlock (2),
412 .BR mmap (2),
413 .BR open (2),
414 .BR quotactl (2),
415 .BR sbrk (2),
416 .BR shmctl (2),
417 .BR sigqueue (2),
418 .BR malloc (3),
419 .BR ulimit (3),
420 .BR capabilities (7),
421 .BR signal (7)