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