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