Clean up references to some obsolete functions in manual pages.
[dragonfly.git] / lib / libc / sys / getrlimit.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  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 8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/sys/getrlimit.2,v 1.10.2.5 2001/12/14 18:34:00 ru Exp $
34 .\"
35 .Dd July 6, 2009
36 .Dt GETRLIMIT 2
37 .Os
38 .Sh NAME
39 .Nm getrlimit ,
40 .Nm setrlimit
41 .Nd control maximum system resource consumption
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In sys/types.h
46 .In sys/time.h
47 .In sys/resource.h
48 .Ft int
49 .Fn getrlimit "int resource" "struct rlimit *rlp"
50 .Ft int
51 .Fn setrlimit "int resource" "const struct rlimit *rlp"
52 .Sh DESCRIPTION
53 Limits on the consumption of system resources by the current process
54 and each process it creates may be obtained with the
55 .Fn getrlimit
56 call, and set with the
57 .Fn setrlimit
58 call.
59 .Pp
60 The
61 .Fa resource
62 parameter is one of the following:
63 .Bl -tag -width RLIMIT_FSIZEAA
64 .It Li RLIMIT_AS
65 The maximum size (in bytes) of a process' total available memory.
66 If this limit is exceeded, the
67 .Xr malloc 3
68 and
69 .Xr mmap 2
70 functions will fail and
71 .Va errno
72 set to
73 .Er ENOMEM .
74 Moreover, the automatic stack growth will fail as well.
75 .It Li RLIMIT_CORE
76 The largest size (in bytes)
77 .Xr core 5
78 file that may be created.
79 .It Li RLIMIT_CPU
80 The maximum amount of cpu time (in seconds) to be used by
81 each process.
82 .It Li RLIMIT_DATA
83 The maximum size (in bytes) of the data segment for a process;
84 this defines how far a program may extend its break with the
85 .Xr sbrk 2
86 system call.
87 .It Li RLIMIT_FSIZE
88 The largest size (in bytes) file that may be created.
89 .It Li RLIMIT_MEMLOCK
90 The maximum size (in bytes) which a process may lock into memory
91 using the
92 .Xr mlock 2
93 function.
94 .It Li RLIMIT_NOFILE
95 The maximum number of open files for this process.
96 .It Li RLIMIT_NPROC
97 The maximum number of simultaneous processes for this user id.
98 .It Li RLIMIT_RSS
99 The maximum size (in bytes) to which a process's resident set size may
100 grow.
101 This imposes a limit on the amount of physical memory to be given to
102 a process; if memory is tight, the system will prefer to take memory
103 from processes that are exceeding their declared resident set size.
104 .It Li RLIMIT_STACK
105 The maximum size (in bytes) of the stack segment for a process;
106 this defines how far a program's stack segment may be extended.
107 Stack extension is performed automatically by the system.
108 .It Li RLIMIT_SBSIZE
109 The maximum size (in bytes) of socket buffer usage for this user.
110 This limits the amount of network memory, and hence the amount of
111 mbufs, that this user may hold at any time.
112 .It Li RLIMIT_POSIXLOCK
113 The maximum number of POSIX-type advisory-mode locks available to
114 this user.
115 .El
116 .Pp
117 A resource limit is specified as a soft limit and a hard limit.
118 When a soft limit is exceeded a process may receive a signal (for example, if
119 the cpu time or file size is exceeded), but it will be allowed to
120 continue execution until it reaches the hard limit (or modifies
121 its resource limit).
122 The
123 .Em rlimit
124 structure is used to specify the hard and soft limits on a resource,
125 .Bd -literal -offset indent
126 struct rlimit {
127         rlim_t  rlim_cur;       /* current (soft) limit */
128         rlim_t  rlim_max;       /* maximum value for rlim_cur */
129 };
130 .Ed
131 .Pp
132 Only the super-user may raise the maximum limits.
133 Other users may only alter
134 .Fa rlim_cur
135 within the range from 0 to
136 .Fa rlim_max
137 or (irreversibly) lower
138 .Fa rlim_max .
139 .Pp
140 An
141 .Dq infinite
142 value for a limit is defined as
143 .Dv RLIM_INFINITY .
144 .Pp
145 Because this information is stored in the per-process information,
146 this system call must be executed directly by the shell if it
147 is to affect all future processes created by the shell;
148 .Ic limit
149 is thus a built-in command to
150 .Xr csh 1 .
151 .Pp
152 The system refuses to extend the data or stack space when the limits
153 would be exceeded in the normal way: a
154 .Xr brk 2
155 call fails if the data space limit is reached.
156 When the stack limit is reached, the process receives
157 a segmentation fault
158 .Pq Dv SIGSEGV ;
159 if this signal is not
160 caught by a handler using the signal stack, this signal
161 will kill the process.
162 .Pp
163 A file I/O operation that would create a file larger than the process'
164 soft limit will cause the write to fail and a signal
165 .Dv SIGXFSZ
166 to be
167 generated; this normally terminates the process, but may be caught.
168 When the soft cpu time limit is exceeded, a signal
169 .Dv SIGXCPU
170 is sent to the
171 offending process.
172 .Sh RETURN VALUES
173 .Rv -std
174 .Sh ERRORS
175 .Fn Getrlimit
176 and
177 .Fn setrlimit
178 will fail if:
179 .Bl -tag -width Er
180 .It Bq Er EFAULT
181 The address specified for
182 .Fa rlp
183 is invalid.
184 .It Bq Er EPERM
185 The limit specified to
186 .Fn setrlimit
187 would have
188 raised the maximum limit value, and the caller is not the super-user.
189 .El
190 .Sh SEE ALSO
191 .Xr csh 1 ,
192 .Xr quota 1 ,
193 .Xr quotactl 2 ,
194 .Xr sigaction 2 ,
195 .Xr sigaltstack 2 ,
196 .Xr sysctl 3 ,
197 .Xr ulimit 3
198 .Sh HISTORY
199 The
200 .Fn getrlimit
201 function call appeared in
202 .Bx 4.2 .