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 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 cdflmnstuv Op val 34.Nm 35.Op Fl C Ar class 36.Op Fl SHB 37.Op Fl cdflmnstuv Op val 38.Op Fl E 39.Op Ar name Ns = Ns Ar value ... 40.Op Ar command 41.Nm 42.Op Fl U Ar user 43.Op Fl SHB 44.Op Fl ea 45.Op Fl cdflmnstuv Op val 46.Nm 47.Op Fl U Ar user 48.Op Fl SHB 49.Op Fl cdflmnstuv Op val 50.Op Fl E 51.Op Ar name Ns = Ns Ar value ... 52.Op Ar command 53.Sh DESCRIPTION 54The 55.Nm 56utility either prints or sets kernel resource limits, and may optionally set 57environment variables like 58.Xr env 1 59and run a program with the selected resources. 60Three uses of the 61.Nm 62command are possible: 63.Pp 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.Pp 140.Bl -tag -width "-d [limit]" 141.It Fl C Ar class 142Use current resource values, modified by the resource entries applicable 143for the login class "class". 144.It Fl U Ar user 145Use current resource values, modified by the resource entries applicable 146to the login class which "user" belongs to. 147If the user does not belong to a class, then the resource capabilities 148for the "default" class are used, if it exists, or the "root" class if 149the user is a superuser account. 150.It Fl S 151Select display or setting of "soft" (or current) resource limits. 152If specific limits settings follow this switch, only soft limits are 153affected unless overridden later with either the 154.Fl H 155or 156.Fl B 157flags. 158.It Fl H 159Select display or setting of "hard" (or maximum) resource limits. 160If specific limits settings follow this switch, only hard limits are 161affected until overridden later with either the 162.Fl S 163or 164.Fl B 165flags. 166.It Fl B 167Select display or setting of both "soft" (current) or "hard" (maximum) 168resource limits. 169If specific limits settings follow this switch, both soft and hard 170limits are affected until overridden later with either the 171.Fl S 172or 173.Fl H 174flags. 175.Fl e 176Select "eval mode" formatting for output. 177This is valid only on display mode and cannot be used when running a 178command. 179The exact syntax used for output depends upon the type of shell from 180which 181.Nm 182is invoked. 183.It Fl b Op Ar limit 184Selects or sets the 185.Em sbsize 186resource limit. 187.It Fl c Op Ar limit 188Select or set (if 'limit' is specified) the 189.Em coredumpsize 190resource limit. 191A value of 0 disables core dumps. 192.It Fl d Op Ar limit 193Select or set (if 'limit' is specified) the 194.Em datasize 195resource limit. 196.It Fl f Op Ar limit 197Select or set the 198.Em filesize 199resource limit. 200.It Fl l Op Ar limit 201Select or set the 202.Em memorylocked 203resource limit. 204.It Fl m Op Ar limit 205Select or set the 206.Em memoryuse 207size limit. 208.It Fl n Op Ar limit 209Select or set the 210.Em openfiles 211resource limit. The system-wide limit on the maximum number of 212open files per process can be viewed using the 'sysctl kern.maxfilesperproc' 213command. The total number of simultaneously open files in the entire 214system is limited to the value displayed by the 'sysctl kern.maxfiles' 215command. 216.It Fl s Op Ar limit 217Select or set the 218.Em stacksize 219resource limit. 220.It Fl t Op Ar limit 221Select or set the 222.Em cputime 223resource limit. 224.It Fl u Op Ar limit 225Select or set the 226.Em maxproc 227resource limit. The system-wide limit on the maximum number of processes 228allowed per UID can be viewed using the 'sysctl kern.maxprocperuid' command. 229The maximum number of processes that can be running simultaneously 230in the entire system is limited to the value given by 231the 'sysctl kern.maxproc' command. 232.It Fl v Op Ar limit 233Select or set the 234.Em virtualmem 235resource limit. 236This limit encompasses the entire VM space for the user process 237and is inclusive of text, data, bss, stack, 238.Xr brk 2 , 239.Xr sbrk 2 240and 241.Xr mmap 2 Ns 'd 242space. 243.El 244.Pp 245Valid values for 246.Ar limit 247in the above set of flags consist of either the 248string 249.Em infinity , 250.Em inf , 251.Em unlimited 252or 253.Em unlimit 254for an infinite (or kernel-defined maximum) 255limit, or a numeric value maybe followed by a suffix. 256Values which relate to size default to a value in bytes, or one of the 257following suffixes may be used as a multiplier: 258.Pp 259.Bl -tag -offset indent -width "xxxx" -compact 260.It b 261512 byte blocks. 262.It k 263kilobytes (1024 bytes). 264.It m 265megabytes (1024*1024 bytes). 266.It g 267gigabytes. 268.It t 269terabytes. 270.El 271.Pp 272The 273.Em cputime 274resource defaults to a number of seconds, but a multiplier may be 275used, and as with size values, multiple values separated by a valid 276suffix are added together: 277.Bl -tag -offset indent -width "xxxx" -compact 278.It s 279seconds. 280.It m 281minutes. 282.It h 283hours. 284.It d 285days. 286.It w 287weeks. 288.It y 289365 day years. 290.El 291.Bl -tag -width indent 292.It Fl E 293The option 294.Sq Fl E 295causes 296.Nm 297to completely ignore the environment it inherits. 298.It Fl a 299This option forces all resource settings to be displayed even if 300other specific resource settings have been specified. 301For example, if you wish to disable core dumps when starting up 302the usenet news system, but wish to set all other resource settings 303as well that apply to the 'news' account, you might use: 304.Pp 305.Dl eval `limits -U news -aBec 0` 306.Pp 307As with the 308.Xr setrlimit 2 309call, only the superuser may raise process "hard" resource limits. 310Non-root users may, however, lower them or change "soft" resource limits 311within to any value below the hard limit. 312When invoked to execute a program, the failure of 313.Nm 314to raise a hard limit is considered a fatal error. 315.El 316.Sh DIAGNOSTICS 317The 318.Nm 319utility 320exits with EXIT_FAILURE if usage is incorrect in any way; i.e. an invalid 321option, or set/display options are selected in the same invocation, 322.Fl e 323is used when running a program, etc. 324When run in display or eval mode, 325.Nm 326exits with a status of EXIT_SUCCESS. 327When run in command mode and execution of the command succeeds, the exit status 328will be whatever the executed program returns. 329.Sh SEE ALSO 330.Xr csh 1 , 331.Xr env 1 , 332.Xr limit 1 , 333.Xr sh 1 , 334.Xr getrlimit 2 , 335.Xr setrlimit 2 , 336.Xr login_cap 3 , 337.Xr login.conf 5 , 338.Xr sysctl 8 339.Sh BUGS 340The 341.Nm 342utility does not handle commands with equal (``='') signs in their 343names, for obvious reasons. 344.Pp 345When eval output is selected, the 346.Pa /proc 347filesystem must be installed 348and mounted for the shell to be correctly determined, and therefore 349output syntax correct for the running shell. 350The default output is valid for 351.Xr sh 1 , 352so this means that any 353usage of 354.Nm 355in eval mode prior mounting 356.Pa /proc 357may only occur in standard bourne 358shell scripts. 359.Pp 360The 361.Nm 362utility makes no effort to ensure that resource settings emitted or displayed 363are valid and settable by the current user. 364Only a superuser account may raise hard limits, and when doing so 365the 366.Fx 367kernel will silently lower limits to values less than 368specified if the values given are too high. 369