xref: /dragonfly/usr.bin/limits/limits.1 (revision 7b0266d8)
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: src/usr.bin/limits/limits.1,v 1.14.2.10 2003/02/25 20:31:18 trhodes Exp $
21.\" $DragonFly: src/usr.bin/limits/limits.1,v 1.4 2004/04/22 17:08:07 dillon Exp $
22.\"
23.Dd January 15, 1996
24.Dt LIMITS 1
25.Os
26.Sh NAME
27.Nm limits
28.Nd set or display process resource limits
29.Sh SYNOPSIS
30.Nm
31.Op Fl C Ar class
32.Op Fl SHB
33.Op Fl ea
34.Op Fl cdfklmnstuv Op val
35.Nm
36.Op Fl C Ar class
37.Op Fl SHB
38.Op Fl cdfklmnstuv Op val
39.Op Fl E
40.Op Ar name Ns = Ns Ar value ...
41.Op Ar command
42.Nm
43.Op Fl U Ar user
44.Op Fl SHB
45.Op Fl ea
46.Op Fl cdflmnstuv Op val
47.Nm
48.Op Fl U Ar user
49.Op Fl SHB
50.Op Fl cdflmnstuv Op val
51.Op Fl E
52.Op Ar name Ns = Ns Ar value ...
53.Op Ar command
54.Sh DESCRIPTION
55The
56.Nm
57utility either prints or sets kernel resource limits, and may optionally set
58environment variables like
59.Xr env 1
60and run a program with the selected resources.
61Three uses of the
62.Nm
63command are possible:
64.Pp
65.Bl -tag -width indent
66.It Xo
67.Nm
68.Op Ar limitflags
69.Op Ar name Ns = Ns Ar value
70.Ar command
71.Xc
72This usage sets limits according to
73.Ar limitflags ,
74optionally sets environment variables given as
75.Ar name Ns = Ns Ar value
76pairs, and then runs the specified command.
77.It Xo
78.Nm
79.Op Ar limitflags
80.Xc
81This usage determines values of resource settings according to
82.Ar limitflags ,
83does not attempt to set them and outputs these values to
84standard output.
85By default, this will output the current kernel resource settings
86active for the calling process.
87Using the
88.Fl C Ar class
89or
90.Fl U Ar user
91flags, you may also display the current resource settings modified
92by the appropriate login class resource limit entries from
93the
94.Xr login.conf 5
95login capabilities database.
96.It Xo
97.Nm
98.Fl e Op Ar limitflags
99.Xc
100This usage determines values of resource settings according to
101.Ar limitflags ,
102but does not set them itself.
103Like the previous usage it outputs these values to standard
104output, except that it will emit them in
105.Em eval
106format, suitable for the calling shell.
107The calling shell is determined by examining the entries in the
108.Pa /proc
109filesystem for the parent process.
110If the shell is known (i.e. it is one of sh, csh, bash, tcsh, ksh,
111pdksh or rc),
112.Nm
113emits 'limit' or 'ulimit' commands in the format understood by
114that shell.
115If the name of the shell cannot be determined, then the 'ulimit'
116format used by
117.Xr sh 1
118is used.
119.Pp
120This is very useful for setting limits used by scripts, or prior
121launching of daemons and other background tasks with specific
122resource limit settings, and provides the benefit of allowing
123global configuration of maximum resource usage by maintaining a
124central database of settings in the login class database.
125.Pp
126Within a shell script,
127.Nm
128will normally be used with eval within backticks as follows:
129.Pp
130.Dl eval `limits -e -C daemon`
131.Pp
132which causes the output of
133.Nm
134to be evaluated and set by the current shell.
135.El
136.Pp
137The value of
138.Ar limitflags
139specified in the above contains one or more of the following options:
140.Pp
141.Bl -tag -width "-d [limit]"
142.It Fl C Ar class
143Use current resource values, modified by the resource entries applicable
144for the login class "class".
145.It Fl U Ar user
146Use current resource values, modified by the resource entries applicable
147to the login class which "user" belongs to.
148If the user does not belong to a class, then the resource capabilities
149for the "default" class are used, if it exists, or the "root" class if
150the user is a superuser account.
151.It Fl S
152Select display or setting of "soft" (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
158flags.
159.It Fl H
160Select display or setting of "hard" (or maximum) resource limits.
161If specific limits settings follow this switch, only hard limits are
162affected until overridden later with either the
163.Fl S
164or
165.Fl B
166flags.
167.It Fl B
168Select display or setting of both "soft" (current) or "hard" (maximum)
169resource limits.
170If specific limits settings follow this switch, both soft and hard
171limits are affected until overridden later with either the
172.Fl S
173or
174.Fl H
175flags.
176.Fl e
177Select "eval mode" formatting for output.
178This is valid only on display mode and cannot be used when running a
179command.
180The exact syntax used for output depends upon the type of shell from
181which
182.Nm
183is invoked.
184.It Fl b Op Ar limit
185Selects or sets the
186.Em sbsize
187resource limit.
188.It Fl c Op Ar limit
189Select or set (if 'limit' is specified) the
190.Em coredumpsize
191resource limit.
192A value of 0 disables core dumps.
193.It Fl d Op Ar limit
194Select or set (if 'limit' is specified) the
195.Em datasize
196resource limit.
197.It Fl f Op Ar limit
198Select or set the
199.Em filesize
200resource limit.
201.It Fl k Op Ar limit
202Select or set the
203.Em posixlocks
204resource limit.
205.It Fl l Op Ar limit
206Select or set the
207.Em memorylocked
208resource limit.
209.It Fl m Op Ar limit
210Select or set the
211.Em memoryuse
212size limit.
213.It Fl n Op Ar limit
214Select or set the
215.Em openfiles
216resource limit.  The system-wide limit on the maximum number of
217open files per process can be viewed using the 'sysctl kern.maxfilesperproc'
218command.  The total number of simultaneously open files in the entire
219system is limited to the value displayed by the 'sysctl kern.maxfiles'
220command.
221.It Fl s Op Ar limit
222Select or set the
223.Em stacksize
224resource limit.
225.It Fl t Op Ar limit
226Select or set the
227.Em cputime
228resource limit.
229.It Fl u Op Ar limit
230Select or set the
231.Em maxproc
232resource limit.  The system-wide limit on the maximum number of processes
233allowed per UID can be viewed using the 'sysctl kern.maxprocperuid' command.
234The maximum number of processes that can be running simultaneously
235in the entire system is limited to the value given by
236the 'sysctl kern.maxproc' command.
237.It Fl v Op Ar limit
238Select or set the
239.Em virtualmem
240resource limit.
241This limit encompasses the entire VM space for the user process
242and is inclusive of text, data, bss, stack,
243.Xr brk 2 ,
244.Xr sbrk 2
245and
246.Xr mmap 2 Ns 'd
247space.
248.El
249.Pp
250Valid values for
251.Ar val
252in the above set of options consist of either the
253string
254.Dq Li infinity ,
255.Dq Li inf ,
256.Dq Li unlimited
257or
258.Dq Li unlimit
259for an infinite (or kernel-defined maximum)
260limit, or a numeric value optionally followed by a suffix.
261Values which relate to size default to a value in bytes, or one of the
262following suffixes may be used as a multiplier:
263.Pp
264.Bl -tag -offset indent -width 4n -compact
265.It Li b
266512 byte blocks.
267.It Li k
268kilobytes (1024 bytes).
269.It Li m
270megabytes (1024*1024 bytes).
271.It Li g
272gigabytes.
273.It Li t
274terabytes.
275.El
276.Pp
277The
278.Va cputime
279resource defaults to a number of seconds, but a multiplier may be
280used, and as with size values, multiple values separated by a valid
281suffix are added together:
282.Pp
283.Bl -tag -offset indent -width 4n -compact
284.It Li s
285seconds.
286.It Li m
287minutes.
288.It Li h
289hours.
290.It Li d
291days.
292.It Li w
293weeks.
294.It Li y
295365 day years.
296.El
297.Bl -tag -width ".Fl C Ar class"
298.It Fl E
299Cause
300.Nm
301to completely ignore the environment it inherits.
302.It Fl a
303Force all resource settings to be displayed even if
304other specific resource settings have been specified.
305For example, if you wish to disable core dumps when starting up
306the Usenet News system, but wish to set all other resource settings
307as well that apply to the
308.Dq Li news
309account, you might use:
310.Pp
311.Dl "eval `limits -U news -aBec 0`"
312.Pp
313As with the
314.Xr setrlimit 2
315call, only the superuser may raise process
316.Dq hard
317resource limits.
318Non-root users may, however, lower them or change
319.Dq soft
320resource limits
321within to any value below the hard limit.
322When invoked to execute a program, the failure of
323.Nm
324to raise a hard limit is considered a fatal error.
325.El
326.Sh DIAGNOSTICS
327The
328.Nm
329utility
330exits with EXIT_FAILURE if usage is incorrect in any way; i.e. an invalid
331option, or set/display options are selected in the same invocation,
332.Fl e
333is used when running a program, etc.
334When run in display or eval mode,
335.Nm
336exits with a status of EXIT_SUCCESS.
337When run in command mode and execution of the command succeeds, the exit status
338will be whatever the executed program returns.
339.Sh SEE ALSO
340.Xr builtin 1 ,
341.Xr csh 1 ,
342.Xr env 1 ,
343.Xr limit 1 ,
344.Xr sh 1 ,
345.Xr getrlimit 2 ,
346.Xr setrlimit 2 ,
347.Xr login_cap 3 ,
348.Xr login.conf 5 ,
349.Xr sysctl 8
350.Sh BUGS
351The
352.Nm
353utility does not handle commands with equal (``='') signs in their
354names, for obvious reasons.
355.Pp
356When eval output is selected, the
357.Pa /proc
358filesystem must be installed
359and mounted for the shell to be correctly determined, and therefore
360output syntax correct for the running shell.
361The default output is valid for
362.Xr sh 1 ,
363so this means that any
364usage of
365.Nm
366in eval mode prior mounting
367.Pa /proc
368may only occur in standard bourne
369shell scripts.
370.Pp
371The
372.Nm
373utility makes no effort to ensure that resource settings emitted or displayed
374are valid and settable by the current user.
375Only a superuser account may raise hard limits, and when doing so
376the
377.Dx
378kernel will silently lower limits to values less than
379specified if the values given are too high.
380