xref: /freebsd/usr.bin/limits/limits.1 (revision c6ec7d31830ab1c80edae95ad5e4b9dba10c47ac)
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 January 23, 2012
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 bcdflmnstuvpw Op Ar val
34.Nm
35.Op Fl C Ar class | Fl U Ar user
36.Op Fl SHB
37.Op Fl bcdflmnstuvpw 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 itself.
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.
90The calling shell is determined by examining the entries in the
91.Pa /proc
92file system for the parent process.
93If the shell is known (i.e., it is one of
94.Nm sh , csh , bash , tcsh , ksh , pdksh
95or
96.Nm rc ) ,
97.Nm
98emits
99.Ic limit
100or
101.Ic ulimit
102commands in the format understood by
103that shell.
104If the name of the shell cannot be determined, then the
105.Ic ulimit
106format used by
107.Xr sh 1
108is used.
109.Pp
110This is very useful for setting limits used by scripts, or prior
111launching of daemons and other background tasks with specific
112resource limit settings, and provides the benefit of allowing
113global configuration of maximum resource usage by maintaining a
114central database of settings in the login class database.
115.Pp
116Within a shell script,
117.Nm
118will normally be used with eval within backticks as follows:
119.Pp
120.Dl "eval `limits -e -C daemon`"
121.Pp
122which causes the output of
123.Nm
124to be evaluated and set by the current shell.
125.El
126.Pp
127The value of
128.Ar limitflags
129specified in the above contains one or more of the following options:
130.Bl -tag -width ".Fl C Ar class"
131.It Fl C Ar class
132Use current resource values, modified by the resource entries applicable
133for the login class
134.Ar class .
135.It Fl U Ar user
136Use current resource values, modified by the resource entries applicable
137to the login class the
138.Ar user
139belongs to.
140If user does not belong to any class, then the resource capabilities
141for the
142.Dq Li default
143class are used, if it exists, or the
144.Dq Li root
145class if the user is a superuser account.
146.It Fl P Ar pid
147Select or set limits for the process identified by the
148.Ar pid .
149.It Fl S
150Select display or setting of
151.Dq soft
152(or current) resource limits.
153If specific limits settings follow this switch, only soft limits are
154affected unless overridden later with either the
155.Fl H
156or
157.Fl B
158options.
159.It Fl H
160Select display or setting of
161.Dq hard
162(or maximum) resource limits.
163If specific limits settings follow this switch, only hard limits are
164affected until overridden later with either the
165.Fl S
166or
167.Fl B
168options.
169.It Fl B
170Select display or setting of both
171.Dq soft
172(current) or
173.Dq hard
174(maximum)
175resource limits.
176If specific limits settings follow this switch, both soft and hard
177limits are affected until overridden later with either the
178.Fl S
179or
180.Fl H
181options.
182.It Fl e
183Select
184.Dq "eval mode"
185formatting for output.
186This is valid only on display mode and cannot be used when running a
187command.
188The exact syntax used for output depends upon the type of shell from
189which
190.Nm
191is invoked.
192.It Fl b Op Ar val
193Select or set the
194.Va sbsize
195resource limit.
196.It Fl c Op Ar val
197Select or set (if
198.Ar val
199is specified) the
200.Va coredumpsize
201resource limit.
202A value of 0 disables core dumps.
203.It Fl d Op Ar val
204Select or set (if
205.Ar val
206is specified) the
207.Va datasize
208resource limit.
209.It Fl f Op Ar val
210Select or set the
211.Va filesize
212resource limit.
213.It Fl l Op Ar val
214Select or set the
215.Va memorylocked
216resource limit.
217.It Fl m Op Ar val
218Select or set the
219.Va memoryuse
220size limit.
221.It Fl n Op Ar val
222Select or set the
223.Va openfiles
224resource limit.
225The system-wide limit on the maximum number of
226open files per process can be viewed by examining the
227.Va kern.maxfilesperproc
228.Xr sysctl 8
229variable.
230The total number of simultaneously open files in the entire
231system is limited to the value displayed by the
232.Va kern.maxfiles
233.Xr sysctl 8
234variable.
235.It Fl s Op Ar val
236Select or set the
237.Va stacksize
238resource limit.
239.It Fl t Op Ar val
240Select or set the
241.Va cputime
242resource limit.
243.It Fl u Op Ar val
244Select or set the
245.Va maxproc
246resource limit.
247The system-wide limit on the maximum number of processes
248allowed per UID can be viewed by examining the
249.Va kern.maxprocperuid
250.Xr sysctl 8
251variable.
252The maximum number of processes that can be running simultaneously
253in the entire system is limited to the value of the
254.Va kern.maxproc
255.Xr sysctl 8
256variable.
257.It Fl v Op Ar val
258Select or set the
259.Va virtualmem
260resource limit.
261This limit encompasses the entire VM space for the user process
262and is inclusive of text, data, bss, stack,
263.Xr brk 2 ,
264.Xr sbrk 2
265and
266.Xr mmap 2 Ns 'd
267space.
268.It Fl p Op Ar val
269Select or set the
270.Va pseudoterminals
271resource limit.
272.It Fl w Op Ar val
273Select or set the
274.Va swapuse
275resource limit.
276.El
277.Pp
278Valid values for
279.Ar val
280in the above set of options consist of either the
281string
282.Dq Li infinity ,
283.Dq Li inf ,
284.Dq Li unlimited
285or
286.Dq Li unlimit
287for an infinite (or kernel-defined maximum)
288limit, or a numeric value optionally followed by a suffix.
289Values which relate to size default to a value in bytes, or one of the
290following suffixes may be used as a multiplier:
291.Pp
292.Bl -tag -offset indent -width 4n -compact
293.It Li b
294512 byte blocks.
295.It Li k
296kilobytes (1024 bytes).
297.It Li m
298megabytes (1024*1024 bytes).
299.It Li g
300gigabytes.
301.It Li t
302terabytes.
303.El
304.Pp
305The
306.Va cputime
307resource defaults to a number of seconds, but a multiplier may be
308used, and as with size values, multiple values separated by a valid
309suffix are added together:
310.Pp
311.Bl -tag -offset indent -width 4n -compact
312.It Li s
313seconds.
314.It Li m
315minutes.
316.It Li h
317hours.
318.It Li d
319days.
320.It Li w
321weeks.
322.It Li y
323365 day years.
324.El
325.Bl -tag -width ".Fl C Ar class"
326.It Fl E
327Cause
328.Nm
329to completely ignore the environment it inherits.
330.It Fl a
331Force all resource settings to be displayed even if
332other specific resource settings have been specified.
333For example, if you wish to disable core dumps when starting up
334the Usenet News system, but wish to set all other resource settings
335as well that apply to the
336.Dq Li news
337account, you might use:
338.Pp
339.Dl "eval `limits -U news -aBec 0`"
340.Pp
341As with the
342.Xr setrlimit 2
343call, only the superuser may raise process
344.Dq hard
345resource limits.
346Non-root users may, however, lower them or change
347.Dq soft
348resource limits
349within to any value below the hard limit.
350When invoked to execute a program, the failure of
351.Nm
352to raise a hard limit is considered a fatal error.
353.El
354.Sh EXIT STATUS
355The
356.Nm
357utility
358exits with
359.Dv EXIT_FAILURE
360if usage is incorrect in any way; i.e., an invalid
361option, or set/display options are selected in the same invocation,
362.Fl e
363is used when running a program, etc.
364When run in display or eval mode,
365.Nm
366exits with a status of
367.Dv EXIT_SUCCESS .
368When run in command mode and execution of the command succeeds, the exit status
369will be whatever the executed program returns.
370.Sh SEE ALSO
371.Xr csh 1 ,
372.Xr env 1 ,
373.Xr limit 1 ,
374.Xr sh 1 ,
375.Xr getrlimit 2 ,
376.Xr setrlimit 2 ,
377.Xr login_cap 3 ,
378.Xr login.conf 5 ,
379.Xr rctl 8 ,
380.Xr sysctl 8
381.Sh BUGS
382The
383.Nm
384utility does not handle commands with equal
385.Pq Ql =
386signs in their
387names, for obvious reasons.
388.Pp
389When eval output is selected, the
390.Pa /proc
391file system must be installed
392and mounted for the shell to be correctly determined, and therefore
393output syntax correct for the running shell.
394The default output is valid for
395.Xr sh 1 ,
396so this means that any
397usage of
398.Nm
399in eval mode prior mounting
400.Pa /proc
401may only occur in standard bourne
402shell scripts.
403.Pp
404The
405.Nm
406utility makes no effort to ensure that resource settings emitted or displayed
407are valid and settable by the current user.
408Only a superuser account may raise hard limits, and when doing so
409the
410.Fx
411kernel will silently lower limits to values less than
412specified if the values given are too high.
413