1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
4 .\" and Copyright (c) 2002 Michael Kerrisk
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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
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.
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
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
62 .TH GETRLIMIT 2 2005-09-20 "Linux" "Linux Programmer's Manual"
64 getrlimit, setrlimit \- get/set resource limits
66 .B #include <sys/time.h>
68 .B #include <sys/resource.h>
70 .BI "int getrlimit(int " resource ", struct rlimit *" rlim );
72 .BI "int setrlimit(int " resource ", const struct rlimit *" rlim );
77 get and set resource limits respectively.
78 Each resource has an associated soft and hard limit, as defined by the
90 rlim_t rlim_cur; /* Soft limit */
91 rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */
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
103 capability) may make arbitrary changes to either limit value.
107 denotes no limit on a resource (both in the structure returned by
109 and in the structure passed to
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
123 which fail with the error
125 upon exceeding this limit.
126 Also automatic stack expansion will fail
129 that kills the process if no alternate stack
130 has been made available via
131 .BR sigaltstack (2)).
132 Since the value is a \fIlong\fP, on machines with a 32-bit \fIlong\fP
133 either this limit is at most 2 GiB, or this resource is unlimited.
139 When 0 no core dump files are created.
140 When non-zero, larger dumps are truncated to this size.
143 CPU time limit in seconds.
144 When the process reaches the soft limit, it is sent a
147 The default action for this signal is to terminate the process.
148 However, the signal can be caught, and the handler can return control to
150 If the process continues to consume CPU time, it will be sent
152 once per second until the hard limit is reached, at which time
155 (This latter point describes Linux 2.2 through 2.6 behaviour.
156 Implementations vary in how they treat processes which continue to
157 consume CPU time after reaching the soft limit.
158 Portable applications that need to catch this signal should
159 perform an orderly termination upon first receipt of
163 The maximum size of the process's data segment (initialized data,
164 uninitialized data, and heap).
165 This limit affects calls to
169 which fail with the error
171 upon encountering the soft limit of this resource.
174 The maximum size of files that the process may create.
175 Attempts to extend a file beyond this limit result in delivery of a
178 By default, this signal terminates a process, but a process can
179 catch this signal instead, in which case the relevant system call (e.g.,
185 .BR RLIMIT_LOCKS " (Early Linux 2.4 only)"
186 .\" to be precise: Linux 2.4.0-test9; no longer in 2.4.25 / 2.5.65
187 A limit on the combined number of
191 leases that this process may establish.
194 The maximum number of bytes of memory that may be locked
196 In effect this limit is rounded down to the nearest multiple
197 of the system page size.
206 Since Linux 2.6.9 it also affects the
209 operation, where it sets a maximum on the total bytes in
210 shared memory segments (see
212 that may be locked by the real user ID of the calling process.
216 locks are accounted for separately from the per-process memory
223 a process can lock bytes up to this limit in each of these
225 In Linux kernels before 2.6.9, this limit controlled the amount of
226 memory that could be locked by a privileged process.
227 Since Linux 2.6.9, no limits are placed on the amount of memory
228 that a privileged process may lock, and this limit instead governs
229 the amount of memory that an unprivileged process may lock.
231 .BR RLIMIT_MSGQUEUE " (Since Linux 2.6.8)"
232 Specifies the limit on the number of bytes that can be allocated
233 for POSIX message queues for the real user ID of the calling process.
234 This limit is enforced for
236 Each message queue that the user creates counts (until it is removed)
237 against this limit according to the formula:
240 bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
241 attr.mq_maxmsg * attr.mq_msgsize
248 structure specified as the fourth argument to
251 The first addend in the formula, which includes
252 .I "sizeof(struct msg_msg *)"
253 (4 bytes on Linux/x86), ensures that the user cannot
254 create an unlimited number of zero-length messages (such messages
255 nevertheless each consume some system memory for bookkeeping overhead).
257 .BR RLIMIT_NICE " (since kernel 2.6.12, but see BUGS below)"
258 Specifies a ceiling to which the process's nice value can be raised using
262 The actual ceiling for the nice value is calculated as
263 .IR "20\ \-\ rlim_cur" .
264 (This strangeness occurs because negative numbers cannot be specified
265 as resource limit values, since they typically have special meanings.
266 For example, RLIM_INFINITY typically is the same as \-1.)
269 Specifies a value one greater than the maximum file descriptor number
270 that can be opened by this process.
276 to exceed this limit yield the error
280 The maximum number of processes (or, more precisely on Linux, threads)
281 that can be created for the real user ID of the calling process.
282 Upon encountering this limit,
288 Specifies the limit (in pages) of the process's resident set
289 (the number of virtual pages resident in RAM).
290 This limit only has effect in Linux 2.4.x, x < 30, and there only
295 .\" As at kernel 2.6.12, this limit still does nothing in 2.6 though
296 .\" talk of making it do something has surfaced from time to time in LKML
299 .BR RLIMIT_RTPRIO " (Since Linux 2.6.12, but see BUGS)"
300 Specifies a ceiling on the real-time priority that may be set for
302 .BR sched_setscheduler (2)
304 .BR sched_setparam (2).
306 .BR RLIMIT_SIGPENDING " (Since Linux 2.6.8)"
307 Specifies the limit on the number of signals
308 that may be queued for the real user ID of the calling process.
309 Both standard and real-time signals are counted for the purpose of
311 However, the limit is only enforced for
313 it is always possible to use
315 to queue one instance of any of the signals that are not already
316 queued to the process.
317 .\" This replaces the /proc/sys/kernel/rtsig-max system-wide limit
318 .\" that was present in kernels <= 2.6.7. MTK Dec 04
321 The maximum size of the process stack, in bytes.
322 Upon reaching this limit, a
325 To handle this signal, a process must employ an alternate signal stack
326 .RB ( sigaltstack (2)).
332 On success, zero is returned.
333 On error, \-1 is returned, and
335 is set appropriately.
340 points outside the accessible address space.
352 An unprivileged process tried to use
355 increase a soft or hard limit above the current hard limit; the
357 capability is required to do this.
358 Or, the process tried to use
361 the soft or hard RLIMIT_NOFILE limit above the current kernel
364 SVr4, 4.3BSD, POSIX.1-2001.
368 derive from BSD and are not specified in POSIX.1-2001;
369 they are present on the BSDs and Linux, but on few other implementations.
371 derives from BSD and is not specified in POSIX.1-2001;
372 it is nevertheless present on most implementations.
373 .BR RLIMIT_MSGQUEUE ,
380 A child process created via
382 inherits its parents resource limits.
383 Resource limits are preserved across
386 In older Linux kernels, the
390 signals delivered when a process encountered the soft and hard
392 limits were delivered one (CPU) second later than they should have been.
393 This was fixed in kernel 2.6.8.
395 In 2.6.x kernels before 2.6.17, a
397 limit of 0 is wrongly treated as "no limit" (like
399 Since kernel 2.6.17, setting a limit of 0 does have an effect,
400 but is actually treated as a limit of 1 second.
401 .\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=114008066530167&w=2
403 A kernel bug means that
405 does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.
407 In kernel 2.6.12, there was an off-by-one mismatch
408 between the priority ranges returned by
412 This had the effect that actual ceiling for the nice value
414 .IR "19\ \-\ rlim_cur" .
415 This was fixed in kernel 2.6.13.
416 .\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=112256338703880&w=2
418 Kernels before 2.4.22 did not diagnose the error
441 .BR capabilities (7),