1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93 33.\" $FreeBSD$ 34.\" 35.Dd June 13, 2004 36.Dt GETRLIMIT 2 37.Os 38.Sh NAME 39.Nm getrlimit , 40.Nm setrlimit 41.Nd control maximum system resource consumption 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.In sys/types.h 46.In sys/time.h 47.In sys/resource.h 48.Ft int 49.Fn getrlimit "int resource" "struct rlimit *rlp" 50.Ft int 51.Fn setrlimit "int resource" "const struct rlimit *rlp" 52.Sh DESCRIPTION 53Limits on the consumption of system resources by the current process 54and each process it creates may be obtained with the 55.Fn getrlimit 56system call, and set with the 57.Fn setrlimit 58system call. 59.Pp 60The 61.Fa resource 62argument is one of the following: 63.Bl -tag -width RLIMIT_FSIZEAA 64.It Dv RLIMIT_AS 65The maximum amount (in bytes) of virtual memory the process is 66allowed to map. 67.It Dv RLIMIT_CORE 68The largest size (in bytes) 69.Xr core 5 70file that may be created. 71.It Dv RLIMIT_CPU 72The maximum amount of cpu time (in seconds) to be used by 73each process. 74.It Dv RLIMIT_DATA 75The maximum size (in bytes) of the data segment for a process; 76this defines how far a program may extend its break with the 77.Xr sbrk 2 78function. 79.It Dv RLIMIT_FSIZE 80The largest size (in bytes) file that may be created. 81.It Dv RLIMIT_MEMLOCK 82The maximum size (in bytes) which a process may lock into memory 83using the 84.Xr mlock 2 85system call. 86.It Dv RLIMIT_NOFILE 87The maximum number of open files for this process. 88.It Dv RLIMIT_NPROC 89The maximum number of simultaneous processes for this user id. 90.It Dv RLIMIT_RSS 91The maximum size (in bytes) to which a process's resident set size may 92grow. 93This imposes a limit on the amount of physical memory to be given to 94a process; if memory is tight, the system will prefer to take memory 95from processes that are exceeding their declared resident set size. 96.It Dv RLIMIT_SBSIZE 97The maximum size (in bytes) of socket buffer usage for this user. 98This limits the amount of network memory, and hence the amount of 99mbufs, that this user may hold at any time. 100.It Dv RLIMIT_STACK 101The maximum size (in bytes) of the stack segment for a process; 102this defines how far a program's stack segment may be extended. 103Stack extension is performed automatically by the system. 104.El 105.Pp 106A resource limit is specified as a soft limit and a hard limit. 107When a 108soft limit is exceeded a process may receive a signal (for example, if 109the cpu time or file size is exceeded), but it will be allowed to 110continue execution until it reaches the hard limit (or modifies 111its resource limit). 112The 113.Vt rlimit 114structure is used to specify the hard and soft limits on a resource, 115.Bd -literal -offset indent 116struct rlimit { 117 rlim_t rlim_cur; /* current (soft) limit */ 118 rlim_t rlim_max; /* maximum value for rlim_cur */ 119}; 120.Ed 121.Pp 122Only the super-user may raise the maximum limits. 123Other users 124may only alter 125.Fa rlim_cur 126within the range from 0 to 127.Fa rlim_max 128or (irreversibly) lower 129.Fa rlim_max . 130.Pp 131An 132.Dq infinite 133value for a limit is defined as 134.Dv RLIM_INFINITY . 135.Pp 136Because this information is stored in the per-process information, 137this system call must be executed directly by the shell if it 138is to affect all future processes created by the shell; 139.Ic limit 140is thus a built-in command to 141.Xr csh 1 . 142.Pp 143The system refuses to extend the data or stack space when the limits 144would be exceeded in the normal way: a 145.Xr brk 2 146function fails if the data space limit is reached. 147When the stack limit is reached, the process receives 148a segmentation fault 149.Pq Dv SIGSEGV ; 150if this signal is not 151caught by a handler using the signal stack, this signal 152will kill the process. 153.Pp 154A file I/O operation that would create a file larger that the process' 155soft limit will cause the write to fail and a signal 156.Dv SIGXFSZ 157to be 158generated; this normally terminates the process, but may be caught. 159When 160the soft cpu time limit is exceeded, a signal 161.Dv SIGXCPU 162is sent to the 163offending process. 164.Sh RETURN VALUES 165.Rv -std 166.Sh ERRORS 167The 168.Fn getrlimit 169and 170.Fn setrlimit 171system calls 172will fail if: 173.Bl -tag -width Er 174.It Bq Er EFAULT 175The address specified for 176.Fa rlp 177is invalid. 178.It Bq Er EPERM 179The limit specified to 180.Fn setrlimit 181would have 182raised the maximum limit value, and the caller is not the super-user. 183.El 184.Sh SEE ALSO 185.Xr csh 1 , 186.Xr quota 1 , 187.Xr quotactl 2 , 188.Xr sigaltstack 2 , 189.Xr sigvec 2 , 190.Xr sysctl 3 , 191.Xr ulimit 3 192.Sh HISTORY 193The 194.Fn getrlimit 195system call appeared in 196.Bx 4.2 . 197