bug report 4.1BSD/sys/25
[unix-history] / usr / src / lib / libc / sys / getrlimit.2
... / ...
CommitLineData
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)getrlimit.2 6.3 (Berkeley) %G%
6.\"
7.TH GETRLIMIT 2 ""
8.UC 4
9.SH NAME
10getrlimit, setrlimit \- control maximum system resource consumption
11.SH SYNOPSIS
12.ft B
13.nf
14#include <sys/time.h>
15#include <sys/resource.h>
16.PP
17.ft B
18getrlimit(resource, rlp)
19int resource;
20struct rlimit *rlp;
21.PP
22.ft B
23setrlimit(resource, rlp)
24int resource;
25struct rlimit *rlp;
26.fi
27.ft R
28.SH DESCRIPTION
29Limits on the consumption of system resources by the current process
30and each process it creates may be obtained with the
31.I getrlimit
32call, and set with the
33.I setrlimit
34call.
35.PP
36The
37.I resource
38parameter is one of the following:
39.TP 17
40RLIMIT_CPU
41the maximum amount of cpu time (in seconds) to be used by
42each process.
43.TP 17
44RLIMIT_FSIZE
45the largest size, in bytes, of any single file that may be created.
46.TP 17
47RLIMIT_DATA
48the maximum size, in bytes, of the data segment for a process;
49this defines how far a program may extend its break with the
50.IR sbrk (2)
51system call.
52.TP 17
53RLIMIT_STACK
54the maximum size, in bytes, of the stack segment for a process;
55this defines how far a program's stack segment may be extended.
56Stack extension is performed automatically by the system.
57.TP 17
58RLIMIT_CORE
59the largest size, in bytes, of a
60.I core
61file that may be created.
62.TP 17
63RLIMIT_RSS
64the maximum size, in bytes, to which a process's resident set size may
65grow. This imposes a limit on the amount of physical memory
66to be given to a process; if memory is tight, the system will
67prefer to take memory from processes that are exceeding their
68declared resident set size.
69.PP
70A resource limit is specified as a soft limit and a hard limit.
71When a soft limit is exceeded a process may receive a signal
72(for example, if the cpu time is exceeded), but it will be allowed
73to continue execution until it reaches the hard limit (or modifies
74its resource limit). The
75.I rlimit
76structure is used to specify the hard and soft limits on a resource,
77.PP
78.nf
79.RS
80.DT
81struct rlimit {
82 int rlim_cur; /* current (soft) limit */
83 int rlim_max; /* hard limit */
84};
85.RE
86.fi
87.PP
88Only the super-user may raise the maximum limits. Other users
89may only alter
90.I rlim_cur
91within the range from 0 to
92.I rlim_max
93or (irreversibly) lower
94.IR rlim_max .
95.PP
96An \*(lqinfinite\*(rq value for a limit is defined as RLIM_INFINITY
97(0x7\&f\&f\&f\&f\&f\&f\&f).
98.PP
99Because this information is stored in the per-process information,
100this system call must be executed directly by the shell if it
101is to affect all future processes created by the shell;
102.I limit
103is thus a built-in command to
104.IR csh (1).
105.PP
106The system refuses to extend the data or stack space when the limits
107would be exceeded in the normal way: a
108.I break
109call fails if the data space limit is reached.
110When the stack limit is reached, the process receives
111a segmentation fault (SIGSEGV); if this signal is not
112caught by a handler using the signal stack, this signal
113will kill the process.
114.PP
115A file I/O operation that would create a file that is too large
116will cause a signal SIGXFSZ to be generated; this normally terminates
117the process, but may be caught.
118When the soft cpu time limit is exceeded, a signal SIGXCPU is sent to the
119offending process.
120.SH "RETURN VALUE
121A 0 return value indicates that the call succeeded, changing
122or returning the resource limit. A return value of \-1 indicates
123that an error occurred, and an error code is stored in the global
124location \fIerrno\fP.
125.SH "ERRORS
126The possible errors are:
127.TP 15
128[EFAULT]
129The address specified for \fIrlp\fP is invalid.
130.TP 15
131[EPERM] The limit specified to \fIsetrlimit\fP would have
132raised the maximum limit value, and the caller is not the super-user.
133.SH SEE ALSO
134csh(1), quota(2), sigvec(2), sigstack(2)
135.SH BUGS
136There should be
137.I limit
138and
139.I unlimit
140commands in
141.IR sh (1)
142as well as in
143.IR csh.