xref: /dragonfly/lib/libc/sys/getrlimit.2 (revision c89a6c1b)
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: src/lib/libc/sys/getrlimit.2,v 1.10.2.5 2001/12/14 18:34:00 ru Exp $
34.\" $DragonFly: src/lib/libc/sys/getrlimit.2,v 1.5 2008/10/17 12:41:38 swildner Exp $
35.\"
36.Dd July 6, 2009
37.Dt GETRLIMIT 2
38.Os
39.Sh NAME
40.Nm getrlimit ,
41.Nm setrlimit
42.Nd control maximum system resource consumption
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In sys/types.h
47.In sys/time.h
48.In sys/resource.h
49.Ft int
50.Fn getrlimit "int resource" "struct rlimit *rlp"
51.Ft int
52.Fn setrlimit "int resource" "const struct rlimit *rlp"
53.Sh DESCRIPTION
54Limits on the consumption of system resources by the current process
55and each process it creates may be obtained with the
56.Fn getrlimit
57call, and set with the
58.Fn setrlimit
59call.
60.Pp
61The
62.Fa resource
63parameter is one of the following:
64.Bl -tag -width RLIMIT_FSIZEAA
65.It Li RLIMIT_AS
66The maximum size (in bytes) of a process' total available memory.
67If this limit is exceeded, the
68.Xr malloc 3
69and
70.Xr mmap 2
71functions will fail and
72.Va errno
73set to
74.Er ENOMEM .
75Moreover, the automatic stack growth will fail as well.
76.It Li RLIMIT_CORE
77The largest size (in bytes)
78.Xr core 5
79file that may be created.
80.It Li RLIMIT_CPU
81The maximum amount of cpu time (in seconds) to be used by
82each process.
83.It Li RLIMIT_DATA
84The maximum size (in bytes) of the data segment for a process;
85this defines how far a program may extend its break with the
86.Xr sbrk 2
87system call.
88.It Li RLIMIT_FSIZE
89The largest size (in bytes) file that may be created.
90.It Li RLIMIT_MEMLOCK
91The maximum size (in bytes) which a process may lock into memory
92using the
93.Xr mlock 2
94function.
95.It Li RLIMIT_NOFILE
96The maximum number of open files for this process.
97.It Li RLIMIT_NPROC
98The maximum number of simultaneous processes for this user id.
99.It Li RLIMIT_RSS
100The maximum size (in bytes) to which a process's resident set size may
101grow.
102This imposes a limit on the amount of physical memory to be given to
103a process; if memory is tight, the system will prefer to take memory
104from processes that are exceeding their declared resident set size.
105.It Li RLIMIT_STACK
106The maximum size (in bytes) of the stack segment for a process;
107this defines how far a program's stack segment may be extended.
108Stack extension is performed automatically by the system.
109.It Li RLIMIT_SBSIZE
110The maximum size (in bytes) of socket buffer usage for this user.
111This limits the amount of network memory, and hence the amount of
112mbufs, that this user may hold at any time.
113.It Li RLIMIT_POSIXLOCK
114The maximum number of POSIX-type advisory-mode locks available to
115this user.
116.El
117.Pp
118A resource limit is specified as a soft limit and a hard limit.
119When a soft limit is exceeded a process may receive a signal (for example, if
120the cpu time or file size is exceeded), but it will be allowed to
121continue execution until it reaches the hard limit (or modifies
122its resource limit).
123The
124.Em rlimit
125structure is used to specify the hard and soft limits on a resource,
126.Bd -literal -offset indent
127struct rlimit {
128	rlim_t	rlim_cur;	/* current (soft) limit */
129	rlim_t	rlim_max;	/* maximum value for rlim_cur */
130};
131.Ed
132.Pp
133Only the super-user may raise the maximum limits.
134Other users may only alter
135.Fa rlim_cur
136within the range from 0 to
137.Fa rlim_max
138or (irreversibly) lower
139.Fa rlim_max .
140.Pp
141An
142.Dq infinite
143value for a limit is defined as
144.Dv RLIM_INFINITY .
145.Pp
146Because this information is stored in the per-process information,
147this system call must be executed directly by the shell if it
148is to affect all future processes created by the shell;
149.Ic limit
150is thus a built-in command to
151.Xr csh 1 .
152.Pp
153The system refuses to extend the data or stack space when the limits
154would be exceeded in the normal way: a
155.Xr brk 2
156call fails if the data space limit is reached.
157When the stack limit is reached, the process receives
158a segmentation fault
159.Pq Dv SIGSEGV ;
160if this signal is not
161caught by a handler using the signal stack, this signal
162will kill the process.
163.Pp
164A file I/O operation that would create a file larger than the process'
165soft limit will cause the write to fail and a signal
166.Dv SIGXFSZ
167to be
168generated; this normally terminates the process, but may be caught.
169When the soft cpu time limit is exceeded, a signal
170.Dv SIGXCPU
171is sent to the
172offending process.
173.Sh RETURN VALUES
174.Rv -std
175.Sh ERRORS
176.Fn Getrlimit
177and
178.Fn setrlimit
179will fail if:
180.Bl -tag -width Er
181.It Bq Er EFAULT
182The address specified for
183.Fa rlp
184is invalid.
185.It Bq Er EPERM
186The limit specified to
187.Fn setrlimit
188would have
189raised the maximum limit value, and the caller is not the super-user.
190.El
191.Sh SEE ALSO
192.Xr csh 1 ,
193.Xr quota 1 ,
194.Xr quotactl 2 ,
195.Xr sigaltstack 2 ,
196.Xr sigvec 2 ,
197.Xr sysctl 3 ,
198.Xr ulimit 3
199.Sh HISTORY
200The
201.Fn getrlimit
202function call appeared in
203.Bx 4.2 .
204