1.\" Copyright (c) 1980, 1991 The Regents of the University of California. 2.\" 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.\" from: @(#)getrlimit.2 6.7 (Berkeley) 3/10/91 33.\" $Id: getrlimit.2,v 1.6 1994/12/08 06:49:43 jtc Exp $ 34.\" 35.Dd March 10, 1991 36.Dt GETRLIMIT 2 37.Os BSD 4 38.Sh NAME 39.Nm getrlimit , 40.Nm setrlimit 41.Nd control maximum system resource consumption 42.Sh SYNOPSIS 43.Fd #include <sys/time.h> 44.Fd #include <sys/resource.h> 45.Ft int 46.Fn getrlimit "int resource" "struct rlimit *rlp" 47.Ft int 48.Fn setrlimit "int resource" "struct rlimit *rlp" 49.Sh DESCRIPTION 50Limits on the consumption of system resources by the current process 51and each process it creates may be obtained with the 52.Fn getrlimit 53call, and set with the 54.Fn setrlimit 55call. 56.Pp 57The 58.Fa resource 59parameter is one of the following: 60.Bl -tag -width RLIMIT_FSIZEAA 61.It Dv RLIMIT_CPU 62the maximum amount of cpu time (in seconds) to be used by 63each process. 64.It Dv RLIMIT_FSIZE 65the largest size, in bytes, of any single file that may be created. 66.It Dv RLIMIT_DATA 67the maximum size, in bytes, of the data segment for a process; 68this defines how far a program may extend its break with the 69.Xr sbrk 2 70system call. 71.It Dv RLIMIT_STACK 72the maximum size, in bytes, of the stack segment for a process; 73this defines how far a program's stack segment may be extended. 74Stack extension is performed automatically by the system. 75.It Dv RLIMIT_CORE 76the largest size, in bytes, of a 77.Xr core 78file that may be created. 79.It Dv RLIMIT_RSS 80the maximum size, in bytes, to which a process's resident set size may 81grow. This imposes a limit on the amount of physical memory 82to be given to a process; if memory is tight, the system will 83prefer to take memory from processes that are exceeding their 84declared resident set size. 85.El 86.Pp 87A resource limit is specified as a soft limit and a hard limit. When a 88soft limit is exceeded a process may receive a signal (for example, if 89the cpu time or file size is exceeded), but it will be allowed to 90continue execution until it reaches the hard limit (or modifies 91its resource limit). The 92.Em rlimit 93structure is used to specify the hard and soft limits on a resource, 94.Bd -literal -offset indent 95struct rlimit { 96 rlim_t rlim_cur; /* current (soft) limit */ 97 rlim_t rlim_max; /* hard limit */ 98}; 99.Ed 100.Pp 101Only the super-user may raise the maximum limits. Other users 102may only alter 103.Fa rlim_cur 104within the range from 0 to 105.Fa rlim_max 106or (irreversibly) lower 107.Fa rlim_max . 108.Pp 109An 110.Dq infinite 111value for a limit is defined as 112.Dv RLIM_INFINITY 113(0x7\&f\&f\&f\&f\&f\&f\&f\&f\&f\&f\&f\&f\&f\&f\&f). 114.Pp 115Because this information is stored in the per-process information, 116this system call must be executed directly by the shell if it 117is to affect all future processes created by the shell; 118.Ic limit 119is thus a built-in command to 120.Xr csh 1 . 121.Pp 122The system refuses to extend the data or stack space when the limits 123would be exceeded in the normal way: a 124.Xr break 125call fails if the data space limit is reached. 126When the stack limit is reached, the process receives 127a segmentation fault 128.Pq Dv SIGSEGV ; 129if this signal is not 130caught by a handler using the signal stack, this signal 131will kill the process. 132.Pp 133A file I/O operation that would create a file larger that the process' 134soft limit will cause the write to fail and a signal 135.Dv SIGXFSZ 136to be 137generated; this normally terminates the process, but may be caught. When 138the soft cpu time limit is exceeded, a signal 139.Dv SIGXCPU 140is sent to the 141offending process. 142.Sh RETURN VALUES 143A 0 return value indicates that the call succeeded, changing 144or returning the resource limit. A return value of -1 indicates 145that an error occurred, and an error code is stored in the global 146location 147.Va errno . 148.Sh ERRORS 149.Fn Getrlimit 150and 151.Fn setrlimit 152will fail if: 153.Bl -tag -width Er 154.It Bq Er EFAULT 155The address specified for 156.Fa rlp 157is invalid. 158.It Bq Er EPERM 159The limit specified to 160.Fn setrlimit 161would have 162raised the maximum limit value, and the caller is not the super-user. 163.El 164.Sh SEE ALSO 165.Xr csh 1 , 166.Xr quota 2 , 167.Xr sigaction 2 , 168.Xr sigstack 2 169.Sh BUGS 170There should be 171.Ic limit 172and 173.Ic unlimit 174commands in 175.Xr sh 1 176as well as in 177.Xr csh . 178.Sh HISTORY 179The 180.Fn getrlimit 181function call appeared in 182.Bx 4.2 . 183