OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / getrlimit.2
index 3b71e66..b12ec14 100644 (file)
@@ -1,8 +1,7 @@
-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
 .\" and Copyright (c) 2002, 2004, 2005, 2008, 2010 Michael Kerrisk
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" manual provided the copyright notice and this permission notice are
 .\" preserved on all copies.
@@ -22,6 +21,7 @@
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
 .\"
 .\" Modified by Michael Haardt <michael@moria.de>
 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
@@ -32,7 +32,7 @@
 .\"          Robert Bihlmeyer <robbe@orcus.ping.at>
 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
 .\" Modified 2001-05-04 by aeb, following a remark by
-.\"          Håvard Lygre <hklygre@online.no>
+.\"          Håvard Lygre <hklygre@online.no>
 .\" Modified 2001-04-17 by Michael Kerrisk <mtk.manpages@gmail.com>
 .\" Modified 2002-06-13 by Michael Kerrisk <mtk.manpages@gmail.com>
 .\"     Added note on nonstandard behavior when SIGCHLD is ignored.
@@ -61,7 +61,7 @@
 .\" 2008-05-07, mtk / Peter Zijlstra, Added description of RLIMIT_RTTIME
 .\" 2010-11-06, mtk: Added documentation of prlimit()
 .\"
-.TH GETRLIMIT 2 2011-09-10 "Linux" "Linux Programmer's Manual"
+.TH GETRLIMIT 2 2015-01-22 "Linux" "Linux Programmer's Manual"
 .SH NAME
 getrlimit, setrlimit, prlimit \- get/set resource limits
 .SH SYNOPSIS
@@ -107,7 +107,7 @@ struct rlimit {
 The soft limit is the value that the kernel enforces for the
 corresponding resource.
 The hard limit acts as a ceiling for the soft limit:
-an unprivileged process may only set its soft limit to a value in the
+an unprivileged process may set only its soft limit to a value in the
 range from 0 up to the hard limit, and (irreversibly) lower its hard limit.
 A privileged process (under Linux: one with the
 .B CAP_SYS_RESOURCE
@@ -129,7 +129,7 @@ The maximum size of the process's virtual memory (address space) in bytes.
 .\" since 2.0.27 / 2.1.12
 This limit affects calls to
 .BR brk (2),
-.BR mmap (2)
+.BR mmap (2),
 and
 .BR mremap (2),
 which fail with the error
@@ -145,9 +145,10 @@ Since the value is a \fIlong\fP, on machines with a 32-bit \fIlong\fP
 either this limit is at most 2 GiB, or this resource is unlimited.
 .TP
 .B RLIMIT_CORE
-Maximum size of
+Maximum size of a
 .I core
-file.
+file (see
+.BR core (5)).
 When 0 no core dump files are created.
 When nonzero, larger dumps are truncated to this size.
 .TP
@@ -240,7 +241,7 @@ Since Linux 2.6.9, no limits are placed on the amount of memory
 that a privileged process may lock, and this limit instead governs
 the amount of memory that an unprivileged process may lock.
 .TP
-.BR RLIMIT_MSGQUEUE " (Since Linux 2.6.8)"
+.BR RLIMIT_MSGQUEUE " (since Linux 2.6.8)"
 Specifies the limit on the number of bytes that can be allocated
 for POSIX message queues for the real user ID of the calling process.
 This limit is enforced for
@@ -249,8 +250,19 @@ Each message queue that the user creates counts (until it is removed)
 against this limit according to the formula:
 .nf
 
-    bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
-            attr.mq_maxmsg * attr.mq_msgsize
+    Since Linux 3.5:
+        bytes = attr.mq_maxmsg * sizeof(struct msg_msg) +
+                min(attr.mq_maxmsg, MQ_PRIO_MAX) *
+                      sizeof(struct posix_msg_tree_node)+
+                                /* For overhead */
+                attr.mq_maxmsg * attr.mq_msgsize;
+                                /* For message data */
+
+    Linux 3.4 and earlier:
+        bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
+                                /* For overhead */
+                attr.mq_maxmsg * attr.mq_msgsize;
+                                /* For message data */
 
 .fi
 where
@@ -258,11 +270,16 @@ where
 is the
 .I mq_attr
 structure specified as the fourth argument to
-.BR mq_open (3).
+.BR mq_open (3),
+and the
+.I msg_msg
+and
+.I posix_msg_tree_node
+structures are kernel-internal structures.
 
-The first addend in the formula, which includes
-.I "sizeof(struct msg_msg *)"
-(4 bytes on Linux/i386), ensures that the user cannot
+The "overhead" addend in the formula accounts for overhead
+bytes required by the implementation
+and ensures that the user cannot
 create an unlimited number of zero-length messages (such messages
 nevertheless each consume some system memory for bookkeeping overhead).
 .TP
@@ -300,12 +317,17 @@ Upon encountering this limit,
 .BR fork (2)
 fails with the error
 .BR EAGAIN .
+This limit is not enforced for processes that have either the
+.B CAP_SYS_ADMIN
+or the
+.B CAP_SYS_RESOURCE
+capability.
 .TP
 .B RLIMIT_RSS
 Specifies the limit (in pages) of the process's resident set
 (the number of virtual pages resident in RAM).
-This limit only has effect in Linux 2.4.x, x < 30, and there only
-affects calls to
+This limit has effect only in Linux 2.4.x, x < 30, and there
+affects only calls to
 .BR madvise (2)
 specifying
 .BR MADV_WILLNEED .
@@ -313,14 +335,14 @@ specifying
 .\" talk of making it do something has surfaced from time to time in LKML
 .\"       -- MTK, Jul 05
 .TP
-.BR RLIMIT_RTPRIO " (Since Linux 2.6.12, but see BUGS)"
+.BR RLIMIT_RTPRIO " (since Linux 2.6.12, but see BUGS)"
 Specifies a ceiling on the real-time priority that may be set for
 this process using
 .BR sched_setscheduler (2)
 and
 .BR sched_setparam (2).
 .TP
-.BR RLIMIT_RTTIME " (Since Linux 2.6.25)"
+.BR RLIMIT_RTTIME " (since Linux 2.6.25)"
 Specifies a limit (in microseconds)
 on the amount of CPU time that a process scheduled
 under a real-time scheduling policy may consume without making a blocking
@@ -346,12 +368,12 @@ signal.
 The intended use of this limit is to stop a runaway
 real-time process from locking up the system.
 .TP
-.BR RLIMIT_SIGPENDING " (Since Linux 2.6.8)"
+.BR RLIMIT_SIGPENDING " (since Linux 2.6.8)"
 Specifies the limit on the number of signals
 that may be queued for the real user ID of the calling process.
 Both standard and real-time signals are counted for the purpose of
 checking this limit.
-However, the limit is only enforced for
+However, the limit is enforced only for
 .BR sigqueue (3);
 it is always possible to use
 .BR kill (2)
@@ -376,6 +398,15 @@ command-line arguments and environment variables; for details, see
 .\" commit c022a0acad534fd5f5d5f17280f6d4d135e74e81
 .\" Author: Jiri Slaby <jslaby@suse.cz>
 .\" Date:   Tue May 4 18:03:50 2010 +0200
+.\"
+.\"     rlimits: implement prlimit64 syscall
+.\"
+.\" commit 6a1d5e2c85d06da35cdfd93f1a27675bfdc3ad8c
+.\" Author: Jiri Slaby <jslaby@suse.cz>
+.\" Date:   Wed Mar 24 17:06:58 2010 +0100
+.\"
+.\"     rlimits: add rlimit64 structure
+.\"
 The Linux-specific
 .BR prlimit ()
 system call combines and extends the functionality of
@@ -424,7 +455,7 @@ must match the real user ID of the caller
 .I and
 the real, effective, and saved set group IDs of the target process
 must match the real group ID of the caller.
-.\" FIXME this permission check is strange
+.\" FIXME this permission check is strange
 .\" Asked about this on LKML, 7 Nov 2010
 .\"     "Inconsistent credential checking in prlimit() syscall"
 .SH RETURN VALUE
@@ -454,11 +485,18 @@ was greater than
 An unprivileged process tried to raise the hard limit; the
 .B CAP_SYS_RESOURCE
 capability is required to do this.
-Or, the caller tried to increase the hard
+.TP
+.B EPERM
+The caller tried to increase the hard
 .B RLIMIT_NOFILE
-limit above the current kernel maximum
-.RB ( NR_OPEN ).
-Or, the calling process did not have permission to set limits
+limit above the maximum defined by
+.IR /proc/sys/fs/nr_open
+(see
+.BR proc (5))
+.TP
+.B EPERM
+.RB ( prlimit ())
+The calling process did not have permission to set limits
 for the process specified by
 .IR pid .
 .TP
@@ -500,6 +538,11 @@ inherits its parent's resource limits.
 Resource limits are preserved across
 .BR execve (2).
 
+Lowering the soft limit for a resource below the process's
+current consumption of that resource will succeed
+(but will prevent the process from further increasing
+its consumption of the resource).
+
 One can set the resource limits of the shell using the built-in
 .IR ulimit
 command
@@ -509,6 +552,11 @@ in
 The shell's resource limits are inherited by the processes that
 it creates to execute commands.
 
+Since Linux 2.6.24, the resource limits of any process can be inspected via
+.IR /proc/[pid]/limits ;
+see
+.BR proc (5).
+
 Ancient systems provided a
 .BR vlimit ()
 function with a similar purpose to
@@ -517,6 +565,148 @@ For backward compatibility, glibc also provides
 .BR vlimit ().
 All new applications should be written using
 .BR setrlimit ().
+.SS C library/ kernel ABI differences
+Since version 2.13, the glibc
+.BR getrlimit ()
+and
+.BR setrlimit ()
+wrapper functions no longer invoke the corresponding system calls,
+but instead employ
+.BR prlimit (),
+for the reasons described in BUGS.
+.SH BUGS
+In older Linux kernels, the
+.B SIGXCPU
+and
+.B SIGKILL
+signals delivered when a process encountered the soft and hard
+.B RLIMIT_CPU
+limits were delivered one (CPU) second later than they should have been.
+This was fixed in kernel 2.6.8.
+
+In 2.6.x kernels before 2.6.17, a
+.B RLIMIT_CPU
+limit of 0 is wrongly treated as "no limit" (like
+.BR RLIM_INFINITY ).
+Since Linux 2.6.17, setting a limit of 0 does have an effect,
+but is actually treated as a limit of 1 second.
+.\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=114008066530167&w=2
+
+A kernel bug means that
+.\" See https://lwn.net/Articles/145008/
+.B RLIMIT_RTPRIO
+does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.
+
+In kernel 2.6.12, there was an off-by-one mismatch
+between the priority ranges returned by
+.BR getpriority (2)
+and
+.BR RLIMIT_NICE .
+This had the effect that the actual ceiling for the nice value
+was calculated as
+.IR "19\ \-\ rlim_cur" .
+This was fixed in kernel 2.6.13.
+.\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=112256338703880&w=2
+
+Since Linux 2.6.12,
+.\" The relevant patch, sent to LKML, seems to be
+.\" http://thread.gmane.org/gmane.linux.kernel/273462
+.\" From: Roland McGrath <roland <at> redhat.com>
+.\" Subject: [PATCH 7/7] make RLIMIT_CPU/SIGXCPU per-process
+.\" Date: 2005-01-23 23:27:46 GMT
+if a process reaches its soft
+.BR RLIMIT_CPU
+limit and has a handler installed for
+.BR SIGXCPU ,
+then, in addition to invoking the signal handler,
+the kernel increases the soft limit by one second.
+This behavior repeats if the process continues to consume CPU time,
+until the hard limit is reached,
+at which point the process is killed.
+Other implementations
+.\" Tested Solaris 10, FreeBSD 9, OpenBSD 5.0
+do not change the
+.BR RLIMIT_CPU
+soft limit in this manner,
+and the Linux behavior is probably not standards conformant;
+portable applications should avoid relying on this Linux-specific behavior.
+.\" FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=50951
+The Linux-specific
+.BR RLIMIT_RTTIME
+limit exhibits the same behavior when the soft limit is encountered.
+
+Kernels before 2.4.22 did not diagnose the error
+.B EINVAL
+for
+.BR setrlimit ()
+when
+.I rlim\->rlim_cur
+was greater than
+.IR rlim\->rlim_max .
+.\"
+.SS Representation of """large""" resource limit values on 32-bit platforms
+The glibc
+.BR getrlimit ()
+and
+.BR setrlimit ()
+wrapper functions use a 64-bit
+.IR rlim_t
+data type, even on 32-bit platforms.
+However, the
+.I rlim_t
+data type used in the
+.BR getrlimit ()
+and
+.BR setrlimit ()
+system calls is a (32-bit)
+.IR "unsigned long" .
+Furthermore, in Linux versions before 2.6.36,
+the kernel represents resource limits on 32-bit platforms as
+.IR "unsigned long" .
+However, a 32-bit data type is not wide enough.
+.\" https://bugzilla.kernel.org/show_bug.cgi?id=5042
+.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=12201
+The most pertinent limit here is
+.BR RLIMIT_FSIZE ,
+which specifies the maximum size to which a file can grow:
+to be useful, this limit must be represented using a type
+that is as wide as the type used to
+represent file offsets\(emthat is, as wide as a 64-bit
+.BR off_t
+(assuming a program compiled with
+.IR _FILE_OFFSET_BITS=64 ).
+
+To work around this kernel limitation,
+if a program tried to set a resource limit to a value larger than
+can be represented in a 32-bit
+.IR "unsigned long" ,
+then the glibc
+.BR setrlimit ()
+wrapper function silently converted the limit value to
+.BR RLIM_INFINITY .
+In other words, the requested resource limit setting was silently ignored.
+
+This problem was addressed in Linux 2.6.36 with two principal changes:
+.IP * 3
+the addition of a new kernel representation of resource limits that
+uses 64 bits, even on 32-bit platforms;
+.IP *
+the addition of the
+.BR prlimit ()
+system call, which employs 64-bit values for its resource limit arguments.
+.PP
+Since version 2.13,
+.\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=12201
+glibc works around the limitations of the
+.BR getrlimit ()
+and
+.BR setrlimit ()
+system calls by implementing
+.BR setrlimit ()
+and
+.BR getrlimit ()
+as wrapper functions that call
+.BR prlimit ().
 .SH EXAMPLE
 The program below demonstrates the use of
 .BR prlimit ().
@@ -573,51 +763,8 @@ main(int argc, char *argv[])
     exit(EXIT_FAILURE);
 }
 .fi
-.SH BUGS
-.\" FIXME prlimit() does not suffer
-.\" https://bugzilla.kernel.org/show_bug.cgi?id=5042
-.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=12201
-In older Linux kernels, the
-.B SIGXCPU
-and
-.B SIGKILL
-signals delivered when a process encountered the soft and hard
-.B RLIMIT_CPU
-limits were delivered one (CPU) second later than they should have been.
-This was fixed in kernel 2.6.8.
-
-In 2.6.x kernels before 2.6.17, a
-.B RLIMIT_CPU
-limit of 0 is wrongly treated as "no limit" (like
-.BR RLIM_INFINITY ).
-Since Linux 2.6.17, setting a limit of 0 does have an effect,
-but is actually treated as a limit of 1 second.
-.\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=114008066530167&w=2
-
-A kernel bug means that
-.B RLIMIT_RTPRIO
-does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.
-
-In kernel 2.6.12, there was an off-by-one mismatch
-between the priority ranges returned by
-.BR getpriority (2)
-and
-.BR RLIMIT_NICE .
-This had the effect that the actual ceiling for the nice value
-was calculated as
-.IR "19\ \-\ rlim_cur" .
-This was fixed in kernel 2.6.13.
-.\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=112256338703880&w=2
-
-Kernels before 2.4.22 did not diagnose the error
-.B EINVAL
-for
-.BR setrlimit ()
-when
-.I rlim\->rlim_cur
-was greater than
-.IR rlim\->rlim_max .
-.SH "SEE ALSO"
+.SH SEE ALSO
+.BR prlimit (1),
 .BR dup (2),
 .BR fcntl (2),
 .BR fork (2),
@@ -634,3 +781,12 @@ was greater than
 .BR core (5),
 .BR capabilities (7),
 .BR signal (7)
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.