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