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