xref: /freebsd/usr.bin/limits/limits.1 (revision 6b13d60bf49ee40626d7e3a5d5a80519f0067307)
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
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.El
284.Pp
285Valid values for
286.Ar val
287in the above set of options consist of either the
288string
289.Dq Li infinity ,
290.Dq Li inf ,
291.Dq Li unlimited
292or
293.Dq Li unlimit
294for an infinite (or kernel-defined maximum)
295limit, or a numeric value optionally followed by a suffix.
296Values which relate to size default to a value in bytes, or one of the
297following suffixes may be used as a multiplier:
298.Pp
299.Bl -tag -offset indent -width 4n -compact
300.It Li b
301512 byte blocks.
302.It Li k
303kilobytes (1024 bytes).
304.It Li m
305megabytes (1024*1024 bytes).
306.It Li g
307gigabytes.
308.It Li t
309terabytes.
310.El
311.Pp
312The
313.Va cputime
314resource defaults to a number of seconds, but a multiplier may be
315used, and as with size values, multiple values separated by a valid
316suffix are added together:
317.Pp
318.Bl -tag -offset indent -width 4n -compact
319.It Li s
320seconds.
321.It Li m
322minutes.
323.It Li h
324hours.
325.It Li d
326days.
327.It Li w
328weeks.
329.It Li y
330365 day years.
331.El
332.Bl -tag -width ".Fl C Ar class"
333.It Fl E
334Cause
335.Nm
336to completely ignore the environment it inherits.
337.It Fl a
338Force all resource settings to be displayed even if
339other specific resource settings have been specified.
340For example, if you wish to disable core dumps when starting up
341the Usenet News system, but wish to set all other resource settings
342as well that apply to the
343.Dq Li news
344account, you might use:
345.Pp
346.Dl "eval `limits -U news -aBec 0`"
347.Pp
348As with the
349.Xr setrlimit 2
350call, only the superuser may raise process
351.Dq hard
352resource limits.
353Non-root users may, however, lower them or change
354.Dq soft
355resource limits
356within to any value below the hard limit.
357When invoked to execute a program, the failure of
358.Nm
359to raise a hard limit is considered a fatal error.
360.El
361.Sh EXIT STATUS
362The
363.Nm
364utility
365exits with
366.Dv EXIT_FAILURE
367if usage is incorrect in any way; i.e., an invalid
368option, or set/display options are selected in the same invocation,
369.Fl e
370is used when running a program, etc.
371When run in display or eval mode,
372.Nm
373exits with a status of
374.Dv EXIT_SUCCESS .
375When run in command mode and execution of the command succeeds, the exit status
376will be whatever the executed program returns.
377.Sh EXAMPLES
378Show current stack size limit:
379.Bd -literal -offset indent
380$ limits -s
381Resource limits (current):
382	  stacksize              524288 kB
383.Ed
384.Pp
385Try to run
386.Xr ls 1
387with 1 byte of
388.Va datasize
389limit:
390.Bd -literal -offset indent
391$ limits -d 1b ls
392Data segment size exceeds process limit
393Abort trap
394.Ed
395.Pp
396Produce
397.Ql eval mode
398output to limit
399.Va sbsize
400to 1 byte.
401Output obtained when command is run from
402.Xr sh 1 :
403.Bd -literal -offset indent
404$ limits -e -b 1b
405ulimit -b 512;
406.Ed
407.Pp
408Same as above from
409.Xr csh 1
410.Bd -literal -offset indent
411% limits -e -b 1b
412limit -h sbsize 512;
413limit 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
427The
428.Nm
429utility first appeared in
430.Fx 2.1.7 .
431.Sh AUTHORS
432The
433.Nm
434utility was written by
435.An David Nugent Aq Mt davidn@FreeBSD.org .
436.Sh BUGS
437The
438.Nm
439utility does not handle commands with equal
440.Pq Ql =
441signs in their
442names, for obvious reasons.
443.Pp
444The
445.Nm
446utility makes no effort to ensure that resource settings emitted or displayed
447are valid and settable by the current user.
448Only a superuser account may raise hard limits, and when doing so
449the
450.Fx
451kernel will silently lower limits to values less than
452specified if the values given are too high.
453