1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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. 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.
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
28 .Dd September 30, 2016
34 .Nd control maximum system resource consumption
42 .Fn getrlimit "int resource" "struct rlimit *rlp"
44 .Fn setrlimit "int resource" "const struct rlimit *rlp"
46 Limits on the consumption of system resources by the current process
47 and each process it creates may be obtained with the
49 system call, and set with the
55 argument is one of the following:
56 .Bl -tag -width RLIMIT_FSIZEAA
58 The maximum amount (in bytes) of virtual memory the process is
61 The largest size (in bytes)
63 file that may be created.
65 The maximum amount of cpu time (in seconds) to be used by
68 The maximum size (in bytes) of the data segment for a process;
69 this defines how far a program may extend its break with the
73 The largest size (in bytes) file that may be created.
75 The maximum number of kqueues this user id is allowed to create.
77 The maximum size (in bytes) which a process may lock into memory
82 The maximum number of open files for this process.
84 The maximum number of simultaneous processes for this user id.
86 The maximum number of pseudo-terminals this user id is allowed to create.
88 When there is memory pressure and swap is available, prioritize eviction of
89 a process' resident pages beyond this amount (in bytes).
90 When memory is not under pressure, this rlimit is effectively ignored.
91 Even when there is memory pressure, the amount of available swap space and some
95 .Xr vm.swap_idle_enabled
96 can affect what happens to processes that have exceeded this size.
98 Processes that exceed their set
100 are not signalled or halted.
101 The limit is merely a hint to the VM daemon to prefer to deactivate pages from
102 processes that have exceeded their set
105 The maximum size (in bytes) of socket buffer usage for this user.
106 This limits the amount of network memory, and hence the amount of
107 mbufs, that this user may hold at any time.
109 The maximum size (in bytes) of the stack segment for a process;
110 this defines how far a program's stack segment may be extended.
111 Stack extension is performed automatically by the system.
113 The maximum size (in bytes) of the swap space that may be reserved or
114 used by all of this user id's processes.
115 This limit is enforced only if bit 1 of the
120 for a complete description of this sysctl.
126 A resource limit is specified as a soft limit and a hard limit.
127 When a soft limit is exceeded, a process might or might not receive a signal.
128 For example, signals are generated when the cpu time or file size is exceeded,
129 but not if the address space or RSS limit is exceeded.
130 A program that exceeds the soft limit is allowed to continue execution until it
131 reaches the hard limit, or modifies its own resource limit.
132 Even reaching the hard limit does not necessarily halt a process.
133 For example, if the RSS hard limit is exceeded, nothing happens.
137 structure is used to specify the hard and soft limits on a resource.
138 .Bd -literal -offset indent
140 rlim_t rlim_cur; /* current (soft) limit */
141 rlim_t rlim_max; /* maximum value for rlim_cur */
145 Only the super-user may raise the maximum limits.
149 within the range from 0 to
151 or (irreversibly) lower
156 value for a limit is defined as
159 Because this information is stored in the per-process information,
160 this system call must be executed directly by the shell if it
161 is to affect all future processes created by the shell;
163 is thus a built-in command to
166 The system refuses to extend the data or stack space when the limits
167 would be exceeded in the normal way: a
169 function fails if the data space limit is reached.
170 When the stack limit is reached, the process receives
173 if this signal is not
174 caught by a handler using the signal stack, this signal
175 will kill the process.
177 A file I/O operation that would create a file larger that the process'
178 soft limit will cause the write to fail and a signal
181 generated; this normally terminates the process, but may be caught.
183 the soft cpu time limit is exceeded, a
185 signal is sent to the
188 When most operations would allocate more virtual memory than allowed by the
191 the operation fails with
193 and no signal is raised.
194 A notable exception is stack extension, described above.
195 If stack extension would allocate more virtual memory than allowed by the soft
200 signal will be delivered.
201 The caller is free to raise the soft address space limit up to the hard limit
202 and retry the allocation.
214 The address specified for
218 The limit specified to
221 raised the maximum limit value, and the caller is not the super-user.
234 system call appeared in