]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getrlimit.2
Removed version number from .TH line
[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 .\" and 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" "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 .I 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.
126 Also automatic stack expansion will fail
127 (and generate a
128 .B SIGSEGV
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.
134 .TP
135 .B RLIMIT_CORE
136 Maximum size of
137 .I core
138 file.
139 When 0 no core dump files are created.
140 When non-zero, larger dumps are truncated to this size.
141 .TP
142 .B RLIMIT_CPU
143 CPU time limit in seconds.
144 When the process reaches the soft limit, it is sent a
145 .B SIGXCPU
146 signal.
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
149 the main program.
150 If the process continues to consume CPU time, it will be sent
151 .B SIGXCPU
152 once per second until the hard limit is reached, at which time
153 it is sent
154 .BR SIGKILL .
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
160 .BR SIGXCPU .)
161 .TP
162 .B RLIMIT_DATA
163 The maximum size of the process's data segment (initialized data,
164 uninitialized data, and heap).
165 This limit affects calls to
166 .BR brk (2)
167 and
168 .BR sbrk (2),
169 which fail with the error
170 .B ENOMEM
171 upon encountering the soft limit of this resource.
172 .TP
173 .B RLIMIT_FSIZE
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
176 .B SIGXFSZ
177 signal.
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.,
180 .BR write (2)
181 .BR truncate (2))
182 fails with the error
183 .BR EFBIG .
184 .TP
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
188 .BR flock (2)
189 locks and
190 .BR fcntl (2)
191 leases that this process may establish.
192 .TP
193 .B RLIMIT_MEMLOCK
194 The maximum number of bytes of memory that may be locked
195 into RAM.
196 In effect this limit is rounded down to the nearest multiple
197 of the system page size.
198 This limit affects
199 .BR mlock (2)
200 and
201 .BR mlockall (2)
202 and the
203 .BR mmap (2)
204 .B MAP_LOCKED
205 operation.
206 Since Linux 2.6.9 it also affects the
207 .BR shmctl (2)
208 .B SHM_LOCK
209 operation, where it sets a maximum on the total bytes in
210 shared memory segments (see
211 .BR shmget (2))
212 that may be locked by the real user ID of the calling process.
213 The
214 .BR shmctl (2)
215 .B SHM_LOCK
216 locks are accounted for separately from the per-process memory
217 locks established by
218 .BR mlock (2),
219 .BR mlockall (2),
220 and
221 .BR mmap (2)
222 .BR MAP_LOCKED ;
223 a process can lock bytes up to this limit in each of these
224 two categories.
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.
230 .TP
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
235 .BR mq_open (3).
236 Each message queue that the user creates counts (until it is removed)
237 against this limit according to the formula:
238 .nf
239
240 bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
241 attr.mq_maxmsg * attr.mq_msgsize
242
243 .fi
244 where
245 .I attr
246 is the
247 .I mq_attr
248 structure specified as the fourth argument to
249 .BR mq_open (3).
250
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).
256 .TP
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
259 .BR setpriority (2)
260 or
261 .BR nice (2).
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.)
267 .TP
268 .B RLIMIT_NOFILE
269 Specifies a value one greater than the maximum file descriptor number
270 that can be opened by this process.
271 Attempts
272 .RB ( open (2),
273 .BR pipe (2),
274 .BR dup (2),
275 etc.)
276 to exceed this limit yield the error
277 .BR EMFILE .
278 .TP
279 .B RLIMIT_NPROC
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,
283 .BR fork (2)
284 fails with the error
285 .BR EAGAIN .
286 .TP
287 .B RLIMIT_RSS
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
291 affects calls to
292 .BR madvise (2)
293 specifying
294 .BR MADV_WILLNEED .
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
297 .\" -- MTK, Jul 05
298 .TP
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
301 this process using
302 .BR sched_setscheduler (2)
303 and
304 .BR sched_setparam (2).
305 .TP
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
310 checking this limit.
311 However, the limit is only enforced for
312 .BR sigqueue (2);
313 it is always possible to use
314 .BR kill (2)
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
319 .TP
320 .B RLIMIT_STACK
321 The maximum size of the process stack, in bytes.
322 Upon reaching this limit, a
323 .B SIGSEGV
324 signal is generated.
325 To handle this signal, a process must employ an alternate signal stack
326 .RB ( sigaltstack (2)).
327 .PP
328 .B RLIMIT_OFILE
329 is the BSD name for
330 .BR RLIMIT_NOFILE .
331 .SH "RETURN VALUE"
332 On success, zero is returned.
333 On error, \-1 is returned, and
334 .I errno
335 is set appropriately.
336 .SH ERRORS
337 .TP
338 .B EFAULT
339 .I rlim
340 points outside the accessible address space.
341 .TP
342 .B EINVAL
343 .I resource
344 is not valid;
345 or, for
346 .BR setrlimit ():
347 .IR rlim->rlim_cur
348 was greater than
349 .IR rlim->rlim_max .
350 .TP
351 .B EPERM
352 An unprivileged process tried to use
353 .BR setrlimit ()
354 to
355 increase a soft or hard limit above the current hard limit; the
356 .B CAP_SYS_RESOURCE
357 capability is required to do this.
358 Or, the process tried to use
359 .BR setrlimit ()
360 to increase
361 the soft or hard RLIMIT_NOFILE limit above the current kernel
362 maximum (NR_OPEN).
363 .SH CONFORMING TO
364 SVr4, 4.3BSD, POSIX.1-2001.
365 .BR RLIMIT_MEMLOCK
366 and
367 .BR RLIMIT_NPROC
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.
370 .BR RLIMIT_RSS
371 derives from BSD and is not specified in POSIX.1-2001;
372 it is nevertheless present on most implementations.
373 .BR RLIMIT_MSGQUEUE ,
374 .BR RLIMIT_NICE ,
375 .BR RLIMIT_RTPRIO ,
376 and
377 .B RLIMIT_SIGPENDING
378 are Linux specific.
379 .SH NOTES
380 A child process created via
381 .BR fork (2)
382 inherits its parents resource limits.
383 Resource limits are preserved across
384 .BR execve (2).
385 .SH BUGS
386 In older Linux kernels, the
387 .B SIGXCPU
388 and
389 .B SIGKILL
390 signals delivered when a process encountered the soft and hard
391 .B RLIMIT_CPU
392 limits were delivered one (CPU) second later than they should have been.
393 This was fixed in kernel 2.6.8.
394
395 In 2.6.x kernels before 2.6.17, a
396 .B RLIMIT_CPU
397 limit of 0 is wrongly treated as "no limit" (like
398 .BR RLIM_INFINITY ).
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
402
403 A kernel bug means that
404 .B RLIMIT_RTPRIO
405 does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.
406
407 In kernel 2.6.12, there was an off-by-one mismatch
408 between the priority ranges returned by
409 .BR getpriority (2)
410 and
411 .BR RLIMIT_NICE .
412 This had the effect that actual ceiling for the nice value
413 was calculated as
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
417
418 Kernels before 2.4.22 did not diagnose the error
419 .B EINVAL
420 for
421 .BR setrlimit ()
422 when
423 .IR rlim->rlim_cur
424 was greater than
425 .IR rlim->rlim_max .
426 .SH "SEE ALSO"
427 .BR dup (2),
428 .BR fcntl (2),
429 .BR fork (2),
430 .BR getrusage (2),
431 .BR mlock (2),
432 .BR mmap (2),
433 .BR open (2),
434 .BR quotactl (2),
435 .BR sbrk (2),
436 .BR shmctl (2),
437 .BR sigqueue (2),
438 .BR malloc (3),
439 .BR ulimit (3),
440 .BR core (5),
441 .BR capabilities (7),
442 .BR signal (7)