Initial import, 0.1 + pk 0.2.4-B1
[unix-history] / lib / libc / sys / getrlimit.2
CommitLineData
15637ed4
RG
1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
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.
19.\"
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.
31.\"
32.\" @(#)getrlimit.2 6.7 (Berkeley) 3/10/91
33.\"
34.Dd March 10, 1991
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
49Limits on the consumption of system resources by the current process
50and each process it creates may be obtained with the
51.Fn getrlimit
52call, and set with the
53.Fn setrlimit
54call.
55.Pp
56The
57.Fa resource
58parameter is one of the following:
59.Bl -tag -width RLIMIT_FSIZEAA
60.It Dv RLIMIT_CPU
61the maximum amount of cpu time (in seconds) to be used by
62each process.
63.It Dv RLIMIT_FSIZE
64the largest size, in bytes, of any single file that may be created.
65.It Dv RLIMIT_DATA
66the maximum size, in bytes, of the data segment for a process;
67this defines how far a program may extend its break with the
68.Xr sbrk 2
69system call.
70.It Dv RLIMIT_STACK
71the maximum size, in bytes, of the stack segment for a process;
72this defines how far a program's stack segment may be extended.
73Stack extension is performed automatically by the system.
74.It Dv RLIMIT_CORE
75the largest size, in bytes, of a
76.Xr core
77file that may be created.
78.It Dv RLIMIT_RSS
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
81to be given to a process; if memory is tight, the system will
82prefer to take memory from processes that are exceeding their
83declared resident set size.
84.El
85.Pp
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
90its resource limit). The
91.Em rlimit
92structure is used to specify the hard and soft limits on a resource,
93.Bd -literal -offset indent
94struct rlimit {
95 int rlim_cur; /* current (soft) limit */
96 int rlim_max; /* hard limit */
97};
98.Ed
99.Pp
100Only the super-user may raise the maximum limits. Other users
101may only alter
102.Fa rlim_cur
103within the range from 0 to
104.Fa rlim_max
105or (irreversibly) lower
106.Fa rlim_max .
107.Pp
108An
109.Dq infinite
110value for a limit is defined as
111.Dv RLIM_INFINITY
112(0x7\&f\&f\&f\&f\&f\&f\&f).
113.Pp
114Because this information is stored in the per-process information,
115this system call must be executed directly by the shell if it
116is to affect all future processes created by the shell;
117.Ic limit
118is thus a built-in command to
119.Xr csh 1 .
120.Pp
121The system refuses to extend the data or stack space when the limits
122would be exceeded in the normal way: a
123.Xr break
124call fails if the data space limit is reached.
125When the stack limit is reached, the process receives
126a segmentation fault
127.Pq Dv SIGSEGV ;
128if this signal is not
129caught by a handler using the signal stack, this signal
130will kill the process.
131.Pp
132A file I/O operation that would create a file larger that the process'
133soft limit will cause the write to fail and a signal
134.Dv SIGXFSZ
135to be
136generated; this normally terminates the process, but may be caught. When
137the soft cpu time limit is exceeded, a signal
138.Dv SIGXCPU
139is sent to the
140offending process.
141.Sh RETURN VALUES
142A 0 return value indicates that the call succeeded, changing
143or returning the resource limit. A return value of -1 indicates
144that an error occurred, and an error code is stored in the global
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
161raised the maximum limit value, and the caller is not the super-user.
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
169There should be
170.Ic limit
171and
172.Ic unlimit
173commands in
174.Xr sh 1
175as well as in
176.Xr csh .
177.Sh HISTORY
178The
179.Nm
180function call appeared in
181.Bx 4.2 .