update from Donn -- fixes for pcc
[unix-history] / usr / src / lib / libc / sys / getrlimit.2
CommitLineData
931b8415 1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
88b3ccf2 2.\" All rights reserved.
b67f7691 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
88b3ccf2 5.\"
931b8415 6.\" @(#)getrlimit.2 6.7 (Berkeley) %G%
b67f7691 7.\"
931b8415
CL
8.Dd
9.Dt GETRLIMIT 2
10.Os BSD 4
11.Sh NAME
12.Nm getrlimit ,
13.Nm setrlimit
14.Nd control maximum system resource consumption
15.Sh SYNOPSIS
16.Fd #include <sys/time.h>
17.Fd #include <sys/resource.h>
18.Ft int
19.Fn getrlimit "int resource" "struct rlimit *rlp"
20.Ft int
21.Fn setrlimit "int resource" "struct rlimit *rlp"
22.Sh DESCRIPTION
0f8ac93b
KM
23Limits on the consumption of system resources by the current process
24and each process it creates may be obtained with the
931b8415 25.Fn getrlimit
0f8ac93b 26call, and set with the
931b8415 27.Fn setrlimit
0f8ac93b 28call.
931b8415 29.Pp
0f8ac93b 30The
931b8415 31.Fa resource
0f8ac93b 32parameter is one of the following:
931b8415
CL
33.Bl -tag -width RLIMIT_FSIZEAA
34.It Dv RLIMIT_CPU
7345eeba 35the maximum amount of cpu time (in seconds) to be used by
0f8ac93b 36each process.
931b8415 37.It Dv RLIMIT_FSIZE
63b0bb9c 38the largest size, in bytes, of any single file that may be created.
931b8415 39.It Dv RLIMIT_DATA
0f8ac93b
KM
40the maximum size, in bytes, of the data segment for a process;
41this defines how far a program may extend its break with the
931b8415 42.Xr sbrk 2
0f8ac93b 43system call.
931b8415 44.It Dv RLIMIT_STACK
0f8ac93b 45the maximum size, in bytes, of the stack segment for a process;
65d38ebd
MK
46this defines how far a program's stack segment may be extended.
47Stack extension is performed automatically by the system.
931b8415 48.It Dv RLIMIT_CORE
0f8ac93b 49the largest size, in bytes, of a
931b8415 50.Xr core
63b0bb9c 51file that may be created.
931b8415 52.It Dv RLIMIT_RSS
65d38ebd
MK
53the maximum size, in bytes, to which a process's resident set size may
54grow. This imposes a limit on the amount of physical memory
0f8ac93b 55to be given to a process; if memory is tight, the system will
63b0bb9c 56prefer to take memory from processes that are exceeding their
0f8ac93b 57declared resident set size.
931b8415
CL
58.El
59.Pp
19a3a68f
KB
60A resource limit is specified as a soft limit and a hard limit. When a
61soft limit is exceeded a process may receive a signal (for example, if
62the cpu time or file size is exceeded), but it will be allowed to
63continue execution until it reaches the hard limit (or modifies
0f8ac93b 64its resource limit). The
931b8415 65.Em rlimit
0f8ac93b 66structure is used to specify the hard and soft limits on a resource,
931b8415 67.Bd -literal -offset indent
0f8ac93b
KM
68struct rlimit {
69 int rlim_cur; /* current (soft) limit */
70 int rlim_max; /* hard limit */
71};
931b8415
CL
72.Ed
73.Pp
0f8ac93b
KM
74Only the super-user may raise the maximum limits. Other users
75may only alter
931b8415 76.Fa rlim_cur
0f8ac93b 77within the range from 0 to
931b8415 78.Fa rlim_max
0f8ac93b 79or (irreversibly) lower
931b8415
CL
80.Fa rlim_max .
81.Pp
82An
83.Dq infinite
84value for a limit is defined as
85.Dv RLIM_INFINITY
0f8ac93b 86(0x7\&f\&f\&f\&f\&f\&f\&f).
931b8415 87.Pp
0f8ac93b 88Because this information is stored in the per-process information,
b67f7691
KM
89this system call must be executed directly by the shell if it
90is to affect all future processes created by the shell;
931b8415 91.Ic limit
b67f7691 92is thus a built-in command to
931b8415
CL
93.Xr csh 1 .
94.Pp
b67f7691 95The system refuses to extend the data or stack space when the limits
0f8ac93b 96would be exceeded in the normal way: a
931b8415 97.Xr break
65d38ebd
MK
98call fails if the data space limit is reached.
99When the stack limit is reached, the process receives
931b8415
CL
100a segmentation fault
101.Pq Dv SIGSEGV ;
102if this signal is not
65d38ebd
MK
103caught by a handler using the signal stack, this signal
104will kill the process.
931b8415 105.Pp
19a3a68f 106A file I/O operation that would create a file larger that the process'
931b8415
CL
107soft limit will cause the write to fail and a signal
108.Dv SIGXFSZ
109to be
19a3a68f 110generated; this normally terminates the process, but may be caught. When
931b8415
CL
111the soft cpu time limit is exceeded, a signal
112.Dv SIGXCPU
113is sent to the
0f8ac93b 114offending process.
931b8415 115.Sh RETURN VALUES
0f8ac93b 116A 0 return value indicates that the call succeeded, changing
931b8415 117or returning the resource limit. A return value of -1 indicates
0f8ac93b 118that an error occurred, and an error code is stored in the global
931b8415
CL
119location
120.Va errno .
121.Sh ERRORS
122.Fn Getrlimit
123and
124.Fn setrlimit
125will fail if:
126.Bl -tag -width Er
127.It Bq Er EFAULT
128The address specified for
129.Fa rlp
130is invalid.
131.It Bq Er EPERM
132The limit specified to
133.Fn setrlimit
134would have
0f8ac93b 135raised the maximum limit value, and the caller is not the super-user.
931b8415
CL
136.El
137.Sh SEE ALSO
138.Xr csh 1 ,
139.Xr quota 2 ,
140.Xr sigvec 2 ,
141.Xr sigstack 2
142.Sh BUGS
b67f7691 143There should be
931b8415 144.Ic limit
b67f7691 145and
931b8415 146.Ic unlimit
b67f7691 147commands in
931b8415 148.Xr sh 1
b67f7691 149as well as in
931b8415
CL
150.Xr csh .
151.Sh HISTORY
152The
153.Nm
154function call appeared in
155.Bx 4.2 .