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 November 1, 2013 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 P Ar pid | Fl U Ar user 31.Op Fl SHB 32.Op Fl ea 33.Op Fl bcdfklmnstuvpw Op Ar val 34.Nm 35.Op Fl C Ar class | Fl U Ar user 36.Op Fl SHB 37.Op Fl bcdfklmnstuvpw 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. 90If the shell is known (i.e., it is one of 91.Nm sh , csh , bash , tcsh , ksh , pdksh 92or 93.Nm rc ) , 94.Nm 95emits 96.Ic limit 97or 98.Ic ulimit 99commands in the format understood by 100that shell. 101If the name of the shell cannot be determined, then the 102.Ic ulimit 103format used by 104.Xr sh 1 105is used. 106.Pp 107This is very useful for setting limits used by scripts, or prior 108launching of daemons and other background tasks with specific 109resource limit settings, and provides the benefit of allowing 110global configuration of maximum resource usage by maintaining a 111central database of settings in the login class database. 112.Pp 113Within a shell script, 114.Nm 115will normally be used with eval within backticks as follows: 116.Pp 117.Dl "eval `limits -e -C daemon`" 118.Pp 119which causes the output of 120.Nm 121to be evaluated and set by the current shell. 122.El 123.Pp 124The value of 125.Ar limitflags 126specified in the above contains one or more of the following options: 127.Bl -tag -width ".Fl C Ar class" 128.It Fl C Ar class 129Use current resource values, modified by the resource entries applicable 130for the login class 131.Ar class . 132.It Fl U Ar user 133Use current resource values, modified by the resource entries applicable 134to the login class the 135.Ar user 136belongs to. 137If user does not belong to any class, then the resource capabilities 138for the 139.Dq Li default 140class are used, if it exists, or the 141.Dq Li root 142class if the user is a superuser account. 143.It Fl P Ar pid 144Select or set limits for the process identified by the 145.Ar pid . 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.It 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 k Op Ar val 211Select or set the 212.Va kqueues 213resource limit. 214.It Fl l Op Ar val 215Select or set the 216.Va memorylocked 217resource limit. 218.It Fl m Op Ar val 219Select or set the 220.Va memoryuse 221size limit. 222.It Fl n Op Ar val 223Select or set the 224.Va openfiles 225resource limit. 226The system-wide limit on the maximum number of 227open files per process can be viewed by examining the 228.Va kern.maxfilesperproc 229.Xr sysctl 8 230variable. 231The total number of simultaneously open files in the entire 232system is limited to the value displayed by the 233.Va kern.maxfiles 234.Xr sysctl 8 235variable. 236.It Fl s Op Ar val 237Select or set the 238.Va stacksize 239resource limit. 240.It Fl t Op Ar val 241Select or set the 242.Va cputime 243resource limit. 244.It Fl u Op Ar val 245Select or set the 246.Va maxproc 247resource limit. 248The system-wide limit on the maximum number of processes 249allowed per UID can be viewed by examining the 250.Va kern.maxprocperuid 251.Xr sysctl 8 252variable. 253The maximum number of processes that can be running simultaneously 254in the entire system is limited to the value of the 255.Va kern.maxproc 256.Xr sysctl 8 257variable. 258.It Fl v Op Ar val 259Select or set the 260.Va virtualmem 261resource limit. 262This limit encompasses the entire VM space for the user process 263and is inclusive of text, data, bss, stack, 264.Xr brk 2 , 265.Xr sbrk 2 266and 267.Xr mmap 2 Ns 'd 268space. 269.It Fl p Op Ar val 270Select or set the 271.Va pseudoterminals 272resource limit. 273.It Fl w Op Ar val 274Select or set the 275.Va swapuse 276resource limit. 277.El 278.Pp 279Valid values for 280.Ar val 281in the above set of options consist of either the 282string 283.Dq Li infinity , 284.Dq Li inf , 285.Dq Li unlimited 286or 287.Dq Li unlimit 288for an infinite (or kernel-defined maximum) 289limit, or a numeric value optionally followed by a suffix. 290Values which relate to size default to a value in bytes, or one of the 291following suffixes may be used as a multiplier: 292.Pp 293.Bl -tag -offset indent -width 4n -compact 294.It Li b 295512 byte blocks. 296.It Li k 297kilobytes (1024 bytes). 298.It Li m 299megabytes (1024*1024 bytes). 300.It Li g 301gigabytes. 302.It Li t 303terabytes. 304.El 305.Pp 306The 307.Va cputime 308resource defaults to a number of seconds, but a multiplier may be 309used, and as with size values, multiple values separated by a valid 310suffix are added together: 311.Pp 312.Bl -tag -offset indent -width 4n -compact 313.It Li s 314seconds. 315.It Li m 316minutes. 317.It Li h 318hours. 319.It Li d 320days. 321.It Li w 322weeks. 323.It Li y 324365 day years. 325.El 326.Bl -tag -width ".Fl C Ar class" 327.It Fl E 328Cause 329.Nm 330to completely ignore the environment it inherits. 331.It Fl a 332Force all resource settings to be displayed even if 333other specific resource settings have been specified. 334For example, if you wish to disable core dumps when starting up 335the Usenet News system, but wish to set all other resource settings 336as well that apply to the 337.Dq Li news 338account, you might use: 339.Pp 340.Dl "eval `limits -U news -aBec 0`" 341.Pp 342As with the 343.Xr setrlimit 2 344call, only the superuser may raise process 345.Dq hard 346resource limits. 347Non-root users may, however, lower them or change 348.Dq soft 349resource limits 350within to any value below the hard limit. 351When invoked to execute a program, the failure of 352.Nm 353to raise a hard limit is considered a fatal error. 354.El 355.Sh EXIT STATUS 356The 357.Nm 358utility 359exits with 360.Dv EXIT_FAILURE 361if usage is incorrect in any way; i.e., an invalid 362option, or set/display options are selected in the same invocation, 363.Fl e 364is used when running a program, etc. 365When run in display or eval mode, 366.Nm 367exits with a status of 368.Dv EXIT_SUCCESS . 369When run in command mode and execution of the command succeeds, the exit status 370will be whatever the executed program returns. 371.Sh SEE ALSO 372.Xr csh 1 , 373.Xr env 1 , 374.Xr limit 1 , 375.Xr sh 1 , 376.Xr getrlimit 2 , 377.Xr setrlimit 2 , 378.Xr login_cap 3 , 379.Xr login.conf 5 , 380.Xr rctl 8 , 381.Xr sysctl 8 382.Sh BUGS 383The 384.Nm 385utility does not handle commands with equal 386.Pq Ql = 387signs in their 388names, for obvious reasons. 389.Pp 390The 391.Nm 392utility makes no effort to ensure that resource settings emitted or displayed 393are valid and settable by the current user. 394Only a superuser account may raise hard limits, and when doing so 395the 396.Fx 397kernel will silently lower limits to values less than 398specified if the values given are too high. 399