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