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