]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/limits/limits.1
Import the NetBSD test suite from ^/vendor/NetBSD/tests/09.30.2014_20.45 ,
[FreeBSD/FreeBSD.git] / usr.bin / limits / limits.1
1 .\" Copyright (c) 1996 David Nugent <davidn@blaze.net.au>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, is permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice immediately at the beginning of the file, without modification,
9 .\"    this list of conditions, and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. This work was done expressly for inclusion into FreeBSD.  Other use
14 .\"    is permitted provided this notation is included.
15 .\" 4. Absolutely no warranty of function or purpose is made by the author
16 .\"    David Nugent.
17 .\" 5. Modifications may be freely made to this file providing the above
18 .\"    conditions are met.
19 .\"
20 .\" $FreeBSD$
21 .\"
22 .Dd November 1, 2013
23 .Dt LIMITS 1
24 .Os
25 .Sh NAME
26 .Nm limits
27 .Nd set or display process resource limits
28 .Sh SYNOPSIS
29 .Nm
30 .Op Fl C Ar class | Fl P Ar pid | Fl U Ar user
31 .Op Fl SHB
32 .Op Fl ea
33 .Op Fl bcdfklmnstuvpw Op Ar val
34 .Nm
35 .Op Fl C Ar class | Fl U Ar user
36 .Op Fl SHB
37 .Op Fl bcdfklmnstuvpw Op Ar val
38 .Op Fl E
39 .Oo
40 .Op Ar name Ns = Ns Ar value ...
41 .Ar command
42 .Oc
43 .Sh DESCRIPTION
44 The
45 .Nm
46 utility either prints or sets kernel resource limits, and may optionally set
47 environment variables like
48 .Xr env 1
49 and run a program with the selected resources.
50 Three uses of the
51 .Nm
52 utility are possible:
53 .Bl -tag -width indent
54 .It Xo
55 .Nm
56 .Op Ar limitflags
57 .Op Ar name Ns = Ns Ar value ...
58 .Ar command
59 .Xc
60 This usage sets limits according to
61 .Ar limitflags ,
62 optionally sets environment variables given as
63 .Ar name Ns = Ns Ar value
64 pairs, and then runs the specified
65 .Ar command .
66 .It Nm Op Ar limitflags
67 This usage determines values of resource settings according to
68 .Ar limitflags ,
69 does not attempt to set them and outputs these values to
70 standard output.
71 By default, this will output the current kernel resource settings
72 active for the calling process.
73 Using the
74 .Fl C Ar class
75 or
76 .Fl U Ar user
77 options, you may also display the current resource settings modified
78 by the appropriate login class resource limit entries from
79 the
80 .Xr login.conf 5
81 login capabilities database.
82 .It Nm Fl e Op Ar limitflags
83 This usage determines values of resource settings according to
84 .Ar limitflags ,
85 but does not set them itself.
86 Like the previous usage, it outputs these values to standard
87 output, except that it will emit them in
88 .Ic eval
89 format, suitable for the calling shell.
90 If the shell is known (i.e., it is one of
91 .Nm sh , csh , bash , tcsh , ksh , pdksh
92 or
93 .Nm rc ) ,
94 .Nm
95 emits
96 .Ic limit
97 or
98 .Ic ulimit
99 commands in the format understood by
100 that shell.
101 If the name of the shell cannot be determined, then the
102 .Ic ulimit
103 format used by
104 .Xr sh 1
105 is used.
106 .Pp
107 This is very useful for setting limits used by scripts, or prior
108 launching of daemons and other background tasks with specific
109 resource limit settings, and provides the benefit of allowing
110 global configuration of maximum resource usage by maintaining a
111 central database of settings in the login class database.
112 .Pp
113 Within a shell script,
114 .Nm
115 will normally be used with eval within backticks as follows:
116 .Pp
117 .Dl "eval `limits -e -C daemon`"
118 .Pp
119 which causes the output of
120 .Nm
121 to be evaluated and set by the current shell.
122 .El
123 .Pp
124 The value of
125 .Ar limitflags
126 specified in the above contains one or more of the following options:
127 .Bl -tag -width ".Fl C Ar class"
128 .It Fl C Ar class
129 Use current resource values, modified by the resource entries applicable
130 for the login class
131 .Ar class .
132 .It Fl U Ar user
133 Use current resource values, modified by the resource entries applicable
134 to the login class the
135 .Ar user
136 belongs to.
137 If user does not belong to any class, then the resource capabilities
138 for the
139 .Dq Li default
140 class are used, if it exists, or the
141 .Dq Li root
142 class if the user is a superuser account.
143 .It Fl P Ar pid
144 Select or set limits for the process identified by the
145 .Ar pid .
146 .It Fl S
147 Select display or setting of
148 .Dq soft
149 (or current) resource limits.
150 If specific limits settings follow this switch, only soft limits are
151 affected unless overridden later with either the
152 .Fl H
153 or
154 .Fl B
155 options.
156 .It Fl H
157 Select display or setting of
158 .Dq hard
159 (or maximum) resource limits.
160 If specific limits settings follow this switch, only hard limits are
161 affected until overridden later with either the
162 .Fl S
163 or
164 .Fl B
165 options.
166 .It Fl B
167 Select display or setting of both
168 .Dq soft
169 (current) or
170 .Dq hard
171 (maximum)
172 resource limits.
173 If specific limits settings follow this switch, both soft and hard
174 limits are affected until overridden later with either the
175 .Fl S
176 or
177 .Fl H
178 options.
179 .It Fl e
180 Select
181 .Dq "eval mode"
182 formatting for output.
183 This is valid only on display mode and cannot be used when running a
184 command.
185 The exact syntax used for output depends upon the type of shell from
186 which
187 .Nm
188 is invoked.
189 .It Fl b Op Ar val
190 Select or set the
191 .Va sbsize
192 resource limit.
193 .It Fl c Op Ar val
194 Select or set (if
195 .Ar val
196 is specified) the
197 .Va coredumpsize
198 resource limit.
199 A value of 0 disables core dumps.
200 .It Fl d Op Ar val
201 Select or set (if
202 .Ar val
203 is specified) the
204 .Va datasize
205 resource limit.
206 .It Fl f Op Ar val
207 Select or set the
208 .Va filesize
209 resource limit.
210 .It Fl k Op Ar val
211 Select or set the
212 .Va kqueues
213 resource limit.
214 .It Fl l Op Ar val
215 Select or set the
216 .Va memorylocked
217 resource limit.
218 .It Fl m Op Ar val
219 Select or set the
220 .Va memoryuse
221 size limit.
222 .It Fl n Op Ar val
223 Select or set the
224 .Va openfiles
225 resource limit.
226 The system-wide limit on the maximum number of
227 open files per process can be viewed by examining the
228 .Va kern.maxfilesperproc
229 .Xr sysctl 8
230 variable.
231 The total number of simultaneously open files in the entire
232 system is limited to the value displayed by the
233 .Va kern.maxfiles
234 .Xr sysctl 8
235 variable.
236 .It Fl s Op Ar val
237 Select or set the
238 .Va stacksize
239 resource limit.
240 .It Fl t Op Ar val
241 Select or set the
242 .Va cputime
243 resource limit.
244 .It Fl u Op Ar val
245 Select or set the
246 .Va maxproc
247 resource limit.
248 The system-wide limit on the maximum number of processes
249 allowed per UID can be viewed by examining the
250 .Va kern.maxprocperuid
251 .Xr sysctl 8
252 variable.
253 The maximum number of processes that can be running simultaneously
254 in the entire system is limited to the value of the
255 .Va kern.maxproc
256 .Xr sysctl 8
257 variable.
258 .It Fl v Op Ar val
259 Select or set the
260 .Va virtualmem
261 resource limit.
262 This limit encompasses the entire VM space for the user process
263 and is inclusive of text, data, bss, stack,
264 .Xr brk 2 ,
265 .Xr sbrk 2
266 and
267 .Xr mmap 2 Ns 'd
268 space.
269 .It Fl p Op Ar val
270 Select or set the
271 .Va pseudoterminals
272 resource limit.
273 .It Fl w Op Ar val
274 Select or set the
275 .Va swapuse
276 resource limit.
277 .El
278 .Pp
279 Valid values for
280 .Ar val
281 in the above set of options consist of either the
282 string
283 .Dq Li infinity ,
284 .Dq Li inf ,
285 .Dq Li unlimited
286 or
287 .Dq Li unlimit
288 for an infinite (or kernel-defined maximum)
289 limit, or a numeric value optionally followed by a suffix.
290 Values which relate to size default to a value in bytes, or one of the
291 following suffixes may be used as a multiplier:
292 .Pp
293 .Bl -tag -offset indent -width 4n -compact
294 .It Li b
295 512 byte blocks.
296 .It Li k
297 kilobytes (1024 bytes).
298 .It Li m
299 megabytes (1024*1024 bytes).
300 .It Li g
301 gigabytes.
302 .It Li t
303 terabytes.
304 .El
305 .Pp
306 The
307 .Va cputime
308 resource defaults to a number of seconds, but a multiplier may be
309 used, and as with size values, multiple values separated by a valid
310 suffix are added together:
311 .Pp
312 .Bl -tag -offset indent -width 4n -compact
313 .It Li s
314 seconds.
315 .It Li m
316 minutes.
317 .It Li h
318 hours.
319 .It Li d
320 days.
321 .It Li w
322 weeks.
323 .It Li y
324 365 day years.
325 .El
326 .Bl -tag -width ".Fl C Ar class"
327 .It Fl E
328 Cause
329 .Nm
330 to completely ignore the environment it inherits.
331 .It Fl a
332 Force all resource settings to be displayed even if
333 other specific resource settings have been specified.
334 For example, if you wish to disable core dumps when starting up
335 the Usenet News system, but wish to set all other resource settings
336 as well that apply to the
337 .Dq Li news
338 account, you might use:
339 .Pp
340 .Dl "eval `limits -U news -aBec 0`"
341 .Pp
342 As with the
343 .Xr setrlimit 2
344 call, only the superuser may raise process
345 .Dq hard
346 resource limits.
347 Non-root users may, however, lower them or change
348 .Dq soft
349 resource limits
350 within to any value below the hard limit.
351 When invoked to execute a program, the failure of
352 .Nm
353 to raise a hard limit is considered a fatal error.
354 .El
355 .Sh EXIT STATUS
356 The
357 .Nm
358 utility
359 exits with
360 .Dv EXIT_FAILURE
361 if usage is incorrect in any way; i.e., an invalid
362 option, or set/display options are selected in the same invocation,
363 .Fl e
364 is used when running a program, etc.
365 When run in display or eval mode,
366 .Nm
367 exits with a status of
368 .Dv EXIT_SUCCESS .
369 When run in command mode and execution of the command succeeds, the exit status
370 will be whatever the executed program returns.
371 .Sh SEE ALSO
372 .Xr csh 1 ,
373 .Xr env 1 ,
374 .Xr limit 1 ,
375 .Xr sh 1 ,
376 .Xr getrlimit 2 ,
377 .Xr setrlimit 2 ,
378 .Xr login_cap 3 ,
379 .Xr login.conf 5 ,
380 .Xr rctl 8 ,
381 .Xr sysctl 8
382 .Sh BUGS
383 The
384 .Nm
385 utility does not handle commands with equal
386 .Pq Ql =
387 signs in their
388 names, for obvious reasons.
389 .Pp
390 The
391 .Nm
392 utility makes no effort to ensure that resource settings emitted or displayed
393 are valid and settable by the current user.
394 Only a superuser account may raise hard limits, and when doing so
395 the
396 .Fx
397 kernel will silently lower limits to values less than
398 specified if the values given are too high.