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