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