]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/sys/getrlimit.2
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 .\" 4. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)getrlimit.2 8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd August 20, 2008
32 .Dt GETRLIMIT 2
33 .Os
34 .Sh NAME
35 .Nm getrlimit ,
36 .Nm setrlimit
37 .Nd control maximum system resource consumption
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In sys/types.h
42 .In sys/time.h
43 .In sys/resource.h
44 .Ft int
45 .Fn getrlimit "int resource" "struct rlimit *rlp"
46 .Ft int
47 .Fn setrlimit "int resource" "const struct rlimit *rlp"
48 .Sh DESCRIPTION
49 Limits on the consumption of system resources by the current process
50 and each process it creates may be obtained with the
51 .Fn getrlimit
52 system call, and set with the
53 .Fn setrlimit
54 system call.
55 .Pp
56 The
57 .Fa resource
58 argument is one of the following:
59 .Bl -tag -width RLIMIT_FSIZEAA
60 .It Dv RLIMIT_AS
61 The maximum amount (in bytes) of virtual memory the process is
62 allowed to map.
63 .It Dv RLIMIT_CORE
64 The largest size (in bytes)
65 .Xr core 5
66 file that may be created.
67 .It Dv RLIMIT_CPU
68 The maximum amount of cpu time (in seconds) to be used by
69 each process.
70 .It Dv RLIMIT_DATA
71 The maximum size (in bytes) of the data segment for a process;
72 this defines how far a program may extend its break with the
73 .Xr sbrk 2
74 function.
75 .It Dv RLIMIT_FSIZE
76 The largest size (in bytes) file that may be created.
77 .It Dv RLIMIT_MEMLOCK
78 The maximum size (in bytes) which a process may lock into memory
79 using the
80 .Xr mlock 2
81 system call.
82 .It Dv RLIMIT_NOFILE
83 The maximum number of open files for this process.
84 .It Dv RLIMIT_NPROC
85 The maximum number of simultaneous processes for this user id.
86 .It Dv RLIMIT_RSS
87 The maximum size (in bytes) to which a process's resident set size may
88 grow.
89 This imposes a limit on the amount of physical memory to be given to
90 a process; if memory is tight, the system will prefer to take memory
91 from processes that are exceeding their declared resident set size.
92 .It Dv RLIMIT_SBSIZE
93 The maximum size (in bytes) of socket buffer usage for this user.
94 This limits the amount of network memory, and hence the amount of
95 mbufs, that this user may hold at any time.
96 .It Dv RLIMIT_STACK
97 The maximum size (in bytes) of the stack segment for a process;
98 this defines how far a program's stack segment may be extended.
99 Stack extension is performed automatically by the system.
100 .It Dv RLIMIT_SWAP
101 The maximum size (in bytes) of the swap space that may be reserved or
102 used by all of this user id's processes.
103 This limit is enforced only if bit 1 of the
104 .Va vm.overcommit
105 sysctl is set.
106 Please see
107 .Xr tuning 7
108 for a complete description of this sysctl.
109 .It Dv RLIMIT_NPTS
110 The maximum number of pseudo-terminals created by this user id.
111 .El
112 .Pp
113 A resource limit is specified as a soft limit and a hard limit.
114 When a
115 soft limit is exceeded a process may receive a signal (for example, if
116 the cpu time or file size is exceeded), but it will be allowed to
117 continue execution until it reaches the hard limit (or modifies
118 its resource limit).
119 The
120 .Vt rlimit
121 structure is used to specify the hard and soft limits on a resource,
122 .Bd -literal -offset indent
123 struct rlimit {
124         rlim_t  rlim_cur;       /* current (soft) limit */
125         rlim_t  rlim_max;       /* maximum value for rlim_cur */
126 };
127 .Ed
128 .Pp
129 Only the super-user may raise the maximum limits.
130 Other users
131 may only alter
132 .Fa rlim_cur
133 within the range from 0 to
134 .Fa rlim_max
135 or (irreversibly) lower
136 .Fa rlim_max .
137 .Pp
138 An
139 .Dq infinite
140 value for a limit is defined as
141 .Dv RLIM_INFINITY .
142 .Pp
143 Because this information is stored in the per-process information,
144 this system call must be executed directly by the shell if it
145 is to affect all future processes created by the shell;
146 .Ic limit
147 is thus a built-in command to
148 .Xr csh 1 .
149 .Pp
150 The system refuses to extend the data or stack space when the limits
151 would be exceeded in the normal way: a
152 .Xr brk 2
153 function fails if the data space limit is reached.
154 When the stack limit is reached, the process receives
155 a segmentation fault
156 .Pq Dv SIGSEGV ;
157 if this signal is not
158 caught by a handler using the signal stack, this signal
159 will kill the process.
160 .Pp
161 A file I/O operation that would create a file larger that the process'
162 soft limit will cause the write to fail and a signal
163 .Dv SIGXFSZ
164 to be
165 generated; this normally terminates the process, but may be caught.
166 When
167 the soft cpu time limit is exceeded, a signal
168 .Dv SIGXCPU
169 is sent to the
170 offending process.
171 .Sh RETURN VALUES
172 .Rv -std
173 .Sh ERRORS
174 The
175 .Fn getrlimit
176 and
177 .Fn setrlimit
178 system calls
179 will fail if:
180 .Bl -tag -width Er
181 .It Bq Er EFAULT
182 The address specified for
183 .Fa rlp
184 is invalid.
185 .It Bq Er EPERM
186 The limit specified to
187 .Fn setrlimit
188 would have
189 raised the maximum limit value, and the caller is not the super-user.
190 .El
191 .Sh SEE ALSO
192 .Xr csh 1 ,
193 .Xr quota 1 ,
194 .Xr quotactl 2 ,
195 .Xr sigaltstack 2 ,
196 .Xr sigaction 2 ,
197 .Xr sysctl 3 ,
198 .Xr ulimit 3
199 .Sh HISTORY
200 The
201 .Fn getrlimit
202 system call appeared in
203 .Bx 4.2 .