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