BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libc / sys / getrlimit.2
CommitLineData
931b8415 1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
88b3ccf2 2.\" All rights reserved.
b67f7691 3.\"
af359dea
C
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
88b3ccf2 19.\"
af359dea
C
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
b67f7691 31.\"
af359dea
C
32.\" @(#)getrlimit.2 6.7 (Berkeley) 3/10/91
33.\"
34.Dd March 10, 1991
931b8415
CL
35.Dt GETRLIMIT 2
36.Os BSD 4
37.Sh NAME
38.Nm getrlimit ,
39.Nm setrlimit
40.Nd control maximum system resource consumption
41.Sh SYNOPSIS
42.Fd #include <sys/time.h>
43.Fd #include <sys/resource.h>
44.Ft int
45.Fn getrlimit "int resource" "struct rlimit *rlp"
46.Ft int
47.Fn setrlimit "int resource" "struct rlimit *rlp"
48.Sh DESCRIPTION
0f8ac93b
KM
49Limits on the consumption of system resources by the current process
50and each process it creates may be obtained with the
931b8415 51.Fn getrlimit
0f8ac93b 52call, and set with the
931b8415 53.Fn setrlimit
0f8ac93b 54call.
931b8415 55.Pp
0f8ac93b 56The
931b8415 57.Fa resource
0f8ac93b 58parameter is one of the following:
931b8415
CL
59.Bl -tag -width RLIMIT_FSIZEAA
60.It Dv RLIMIT_CPU
7345eeba 61the maximum amount of cpu time (in seconds) to be used by
0f8ac93b 62each process.
931b8415 63.It Dv RLIMIT_FSIZE
63b0bb9c 64the largest size, in bytes, of any single file that may be created.
931b8415 65.It Dv RLIMIT_DATA
0f8ac93b
KM
66the maximum size, in bytes, of the data segment for a process;
67this defines how far a program may extend its break with the
931b8415 68.Xr sbrk 2
0f8ac93b 69system call.
931b8415 70.It Dv RLIMIT_STACK
0f8ac93b 71the maximum size, in bytes, of the stack segment for a process;
65d38ebd
MK
72this defines how far a program's stack segment may be extended.
73Stack extension is performed automatically by the system.
931b8415 74.It Dv RLIMIT_CORE
0f8ac93b 75the largest size, in bytes, of a
931b8415 76.Xr core
63b0bb9c 77file that may be created.
931b8415 78.It Dv RLIMIT_RSS
65d38ebd
MK
79the maximum size, in bytes, to which a process's resident set size may
80grow. This imposes a limit on the amount of physical memory
0f8ac93b 81to be given to a process; if memory is tight, the system will
63b0bb9c 82prefer to take memory from processes that are exceeding their
0f8ac93b 83declared resident set size.
931b8415
CL
84.El
85.Pp
19a3a68f
KB
86A resource limit is specified as a soft limit and a hard limit. When a
87soft limit is exceeded a process may receive a signal (for example, if
88the cpu time or file size is exceeded), but it will be allowed to
89continue execution until it reaches the hard limit (or modifies
0f8ac93b 90its resource limit). The
931b8415 91.Em rlimit
0f8ac93b 92structure is used to specify the hard and soft limits on a resource,
931b8415 93.Bd -literal -offset indent
0f8ac93b
KM
94struct rlimit {
95 int rlim_cur; /* current (soft) limit */
96 int rlim_max; /* hard limit */
97};
931b8415
CL
98.Ed
99.Pp
0f8ac93b
KM
100Only the super-user may raise the maximum limits. Other users
101may only alter
931b8415 102.Fa rlim_cur
0f8ac93b 103within the range from 0 to
931b8415 104.Fa rlim_max
0f8ac93b 105or (irreversibly) lower
931b8415
CL
106.Fa rlim_max .
107.Pp
108An
109.Dq infinite
110value for a limit is defined as
111.Dv RLIM_INFINITY
0f8ac93b 112(0x7\&f\&f\&f\&f\&f\&f\&f).
931b8415 113.Pp
0f8ac93b 114Because this information is stored in the per-process information,
b67f7691
KM
115this system call must be executed directly by the shell if it
116is to affect all future processes created by the shell;
931b8415 117.Ic limit
b67f7691 118is thus a built-in command to
931b8415
CL
119.Xr csh 1 .
120.Pp
b67f7691 121The system refuses to extend the data or stack space when the limits
0f8ac93b 122would be exceeded in the normal way: a
931b8415 123.Xr break
65d38ebd
MK
124call fails if the data space limit is reached.
125When the stack limit is reached, the process receives
931b8415
CL
126a segmentation fault
127.Pq Dv SIGSEGV ;
128if this signal is not
65d38ebd
MK
129caught by a handler using the signal stack, this signal
130will kill the process.
931b8415 131.Pp
19a3a68f 132A file I/O operation that would create a file larger that the process'
931b8415
CL
133soft limit will cause the write to fail and a signal
134.Dv SIGXFSZ
135to be
19a3a68f 136generated; this normally terminates the process, but may be caught. When
931b8415
CL
137the soft cpu time limit is exceeded, a signal
138.Dv SIGXCPU
139is sent to the
0f8ac93b 140offending process.
931b8415 141.Sh RETURN VALUES
0f8ac93b 142A 0 return value indicates that the call succeeded, changing
931b8415 143or returning the resource limit. A return value of -1 indicates
0f8ac93b 144that an error occurred, and an error code is stored in the global
931b8415
CL
145location
146.Va errno .
147.Sh ERRORS
148.Fn Getrlimit
149and
150.Fn setrlimit
151will fail if:
152.Bl -tag -width Er
153.It Bq Er EFAULT
154The address specified for
155.Fa rlp
156is invalid.
157.It Bq Er EPERM
158The limit specified to
159.Fn setrlimit
160would have
0f8ac93b 161raised the maximum limit value, and the caller is not the super-user.
931b8415
CL
162.El
163.Sh SEE ALSO
164.Xr csh 1 ,
165.Xr quota 2 ,
166.Xr sigvec 2 ,
167.Xr sigstack 2
168.Sh BUGS
b67f7691 169There should be
931b8415 170.Ic limit
b67f7691 171and
931b8415 172.Ic unlimit
b67f7691 173commands in
931b8415 174.Xr sh 1
b67f7691 175as well as in
931b8415
CL
176.Xr csh .
177.Sh HISTORY
178The
179.Nm
180function call appeared in
181.Bx 4.2 .