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