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