xref: /freebsd/usr.bin/limits/limits.1 (revision 952d112864d8008aa87278a30a539d888a8493cd)
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.\"	$Id$
21.\"
22.Dd January 15, 1996
23.Dt LIMITS 1
24.Os FreeBSD
25.Sh NAME
26.Nm limits
27.Nd Set or display process resource limits
28.Sh SYNOPSIS
29.Nm limits
30.Op Fl C Ar class | Fl U Ar user
31.Op Fl SHB
32.Op Fl e
33.Op Fl cdflmnstu Op val
34.Nm limits
35.Op Fl C Ar class | Fl U Ar user
36.Op Fl SHB
37.Op Fl cdflmnstu Op val
38.Op Fl E
39.Op Ar name=value ...
40.Op Ar command
41.Sh DESCRIPTION
42.Nm Limits
43ether prints or sets kernel resource limits, and may optionally set
44environment variables like
45.Xr env 1
46and run a program with the selected resources.
47Three uses of the
48.Nm limits
49command are possible:
50.Pp
51.Bl -hang -width indent
52.It Nm limits Op Ar limitflags
53.Op Ar name=value
54.Ar command
55.Pp
56This usage sets limits according to
57.Ar limitflags ,
58optionally sets environment variables given as
59.Ar name=value
60pairs, and then runs the specified command.
61.It Nm limits Op Ar limitflags
62.Pp
63This usage determines values of resource settings according to
64.Ar limitflags ,
65does not attempt to set them and outputs these values to
66standard output.
67By default, this will output the current kernel resource settings
68active for the calling process.
69Using the
70.Fl C Ar class
71or
72.Fl U Ar user
73flags, you may also display the current resource settings modified
74by the the appropriate login class resource limit entries from
75the
76.Xr login.conf 5
77login capabilities database.
78.It Nm limits Fl e Op Ar limitflags
79.Pp
80This usage determines values of resource settings according to
81.Ar limitflags ,
82but does not set them itself.
83Like the previous usage it outputs these values to standard
84output, except that it will emit them in
85.Em eval
86format, suitable for the calling shell.
87The calling shell is determined by examining the entries in the
88.Pa /proc
89filesystem for the parent process.
90If the shell is known (ie. it is one of sh, csh, bash, tcsh, ksh,
91pdksh or rc),
92.Nm limits
93emits 'limit' or 'ulimit' commands in the format understood by
94that shell.
95If the name of the shell cannot be determined, then the 'ulimit'
96format used by
97.Pa /bin/sh
98is used.
99.Pp
100This is very useful for setting limits used by scripts, or prior
101launching of daemons and other background tasks with specific
102resource limit settings, and provides the benefit of allowing
103global configuration of maximum resource usage by maintaining a
104central database of settings in the login class database.
105.Pp
106Within a shell script,
107.Nm limits
108will normally be used with eval within backticks as follows:
109.Pp
110.Dl eval `limits -e -C daemon`
111.Pp
112which causes the output of
113.Nm limits
114to be evaluated and set by the current shell.
115.El
116.Pp
117The value of limitflags specified in the above contains one or more of the
118following options:
119.Pp
120.Bl -tag -width "-d [limit]"
121.It Fl C Ar class
122Use current resource values, modified by the resource entries applicable
123for the login class "class".
124.It Fl U Ar user
125Use current resource values, modified by the resource entries applicable
126to the login class which "user" belongs to.
127If the user does not belong to a class, then the resource capabilities
128for the "default" class are used, if it exists, or the "root" class if
129the user is a superuser account.
130.It Fl S
131Selects display or setting of "soft" (or current) resource limits.
132If specific limits settings follow this switch, only soft limits are
133affected unless overridden later with either the
134.Fl H
135or
136.Fl B
137flags.
138.It Fl H
139Selects display or setting of "hard" (or maximum) resource limits.
140If specific limits settings follow this switch, only hard limits are
141affected until overridden later with either the
142.Fl S
143or
144.Fl B
145flags.
146.It Fl B
147Selects display or setting of both "soft" (current) or "hard" (maximum)
148resource limits.
149If specific limits settings follow this switch, both soft and hard
150limits are affected until overridden later with either the
151.Fl S
152or
153.Fl H
154flags.
155.Fl e
156Selects "eval mode" formatting for output.
157This is valid only on display mode and cannot be used when running a
158command.
159The exact syntax used for output depeneds upon the type of shell from
160which
161.Nm limits
162is invoked.
163.It Fl c Op Ar limit
164Selects or sets (if 'limit' is specified) the
165.Em coredumsize
166resource limit.
167A value of 0 disables core dumps.
168.It Fl d Op Ar limit
169Selects or sets (if 'limit' is specified) the
170.Em datasize
171resource limit.
172.It Fl f Op Ar limit
173Selects or sets the
174.Em filesize
175resource limit.
176.It Fl l Op Ar limit
177Selects or sets the
178.Em memorylocked
179resource limit.
180.It Fl m Op Ar limit
181Selects or sets the
182.Em memoryuse
183size limit
184.It Fl n Op Ar limit
185Selects or sets the
186.Em openfiles
187resource limit.
188.It Fl s Op Ar limit
189Selects or sets the
190.Em stacksize
191resource limit.
192.It Fl t Op Ar limit
193Selects or sets the
194.Em cputime
195resource limit.
196.It Fl u Op Ar limit
197Selects or sets the
198.Em maxproc
199resource limit.
200.Pp
201Valid values for 'limit' in the above set of flags consist of either the
202string 'infinity' or 'inf' for an infinite (or kernel-defined maximum)
203limit, or a numeric value maybe followed by a suffix.
204Values which relate to size default to a value in bytes, or one of the
205following suffixes may be used as a multiplier:
206.Pp
207.Bl -tag -offset indent -width "xxxx" -compact
208.It b
209512 byte blocks.
210.It k
211kilobytes (1024 bytes).
212.It m
213megabytes (1024*1024 bytes).
214.It g
215gigabytes.
216.It t
217terrabytes.
218.El
219.Pp
220The
221.Em cputime
222resource defaults to a number of seconds, but a multiplier may be
223used, and as with size values, multiple values separated by a valid
224suffix are added together:
225.Bl -tag -offset indent -width "xxxx" -compact
226.It s
227seconds.
228.It m
229minutes.
230.It h
231hours.
232.It d
233days.
234.It w
235weeks.
236.It y
237365 day years.
238.El
239.Pp
240.It Fl E
241The option
242.Sq Fl E
243causes
244.Nm limits
245to completely ignore the environment it inherits.
246.It Fl a
247This option forces all resource settings to be displayed even if
248other specific resource settings have been specified.
249For example, if you wish to disable core dumps when starting up
250the usenet news system, but wish to set all other resource settings
251as well that apply to the 'news' account, you might use:
252.Pp
253.Dl eval `limits -U news -aBec 0`
254.Pp
255As with the
256.Xr setrlimit 3
257call, only the superuser may raise process "hard" resource limits.
258Non-root users may, however, lower them or change "soft" resource limits
259within to any value below the hard limit.
260When invoked to execute a program, the failure of
261.Nm limits
262to raise a hard limit is considered a fatal error.
263.El
264.Sh DIAGNOSTICS
265.Nm Limits
266exits with EXIT_FAILURE if usage is incorrect in any way; ie. an invalid
267option, or set/display options are selected in the same invocation,
268.Fl e
269is used when running a program, etc.
270When run in display or eval mode,
271.Nm limits
272exits with with a status of EXIT_SUCCESS.
273When run in command mode and execution of the command succeeds, the exit status
274will be whatever the executed program returns.
275.Sh SEE ALSO
276.Xr csh 1 ,
277.Xr env 1 ,
278.Xr limit 1 ,
279.Xr sh 1 ,
280.Xr ulimit 1 ,
281.Xr getrlimit 3 ,
282.Xr setrlimit 3 ,
283.Xr login_cap 3 ,
284.Xr login.conf 5
285.Sh BUGS
286.Nm Limits
287does not handle commands with equal (``='') signs in their
288names, for obvious reasons.
289.Pp
290When eval output is selected, the /proc filesystem must be installed
291and mounted for the shell to be correctly determined, and therefore
292output syntax correct for the running shell.
293The default output is valid for /bin/sh, so this means that any
294usage of
295.Nm limits
296in eval mode prior mounting /proc may only occur in standard bourne
297shell scripts.
298.Pp
299.Nm Limits
300makes no effort to ensure that resource settings emitted or displayed
301are valid and settable by the current user.
302Only a superuser account may raise hard limits, and and when doing so
303the FreeBSD kernel will silently lower limits to values less than
304specified if the values given are too high.
305