1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
4 .\" 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 2.6.13" "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. Also automatic stack expansion will fail
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.
137 file. When 0 no core dump files are created.
138 When non-zero, larger dumps are truncated to this size.
141 CPU time limit in seconds.
142 When the process reaches the soft limit, it is sent a
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
148 If the process continues to consume CPU time, it will be sent
150 once per second until the hard limit is reached, at which time
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
161 The maximum size of the process's data segment (initialized data,
162 uninitialized data, and heap).
163 This limit affects calls to
167 which fail with the error
169 upon encountering the soft limit of this resource.
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
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.,
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
189 leases that this process may establish.
192 The maximum number of bytes of memory that may be locked
194 In effect this limit is rounded down to the nearest multiple
195 of the system page size.
204 Since Linux 2.6.9 it also affects the
207 operation, where it sets a maximum on the total bytes in
208 shared memory segments (see
210 that may be locked by the real user ID of the calling process.
214 locks are accounted for separately from the per-process memory
221 a process can lock bytes up to this limit in each of these
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.
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
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:
239 bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
240 attr.mq_maxmsg * attr.mq_msgsize
247 structure specified as the fourth argument to
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).
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
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.)
268 Specifies a value one greater than the maximum file descriptor number
269 that can be opened by this process.
275 to exceed this limit yield the error
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,
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
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
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
301 .BR sched_setscheduler (2)
303 .BR sched_setparam (2).
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
310 However, the limit is only enforced for
312 it is always possible to use
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
320 The maximum size of the process stack, in bytes.
321 Upon reaching this limit, a
324 To handle this signal, a process must employ an alternate signal stack
325 .RB ( sigaltstack (2)).
331 On success, zero is returned. On error, \-1 is returned, and
333 is set appropriately.
338 points outside the accessible address space.
350 An unprivileged process tried to use \fBsetrlimit\fP() to
351 increase a soft or hard limit above the current hard limit; the
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
358 In older Linux kernels, the
362 signals delivered when a process encountered the soft and hard
364 limits were delivered one (CPU) second later than they should have been.
365 This was fixed in kernel 2.6.8.
367 A kernel bug means that
369 does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.
371 In kernel 2.6.12, there was an off-by-one mismatch
372 between the priority ranges returned by
376 This had the effect that actual ceiling for the nice value
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
382 Kernels before 2.4.22 did not diagnose the error
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.
398 derives from BSD and is not specified in POSIX.1-2001;
399 it is nevertheless present on most implementations.
400 .BR RLIMIT_MSGQUEUE ,
420 .BR capabilities (7),