sockaddr's now require length (K. Sklower);
[unix-history] / usr / src / lib / libc / sys / getrlimit.2
CommitLineData
b67f7691
KM
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.\"
19a3a68f 5.\" @(#)getrlimit.2 6.4 (Berkeley) %G%
b67f7691 6.\"
7345eeba 7.TH GETRLIMIT 2 ""
b67f7691
KM
8.UC 4
9.SH NAME
0f8ac93b 10getrlimit, setrlimit \- control maximum system resource consumption
b67f7691 11.SH SYNOPSIS
0f8ac93b
KM
12.ft B
13.nf
14#include <sys/time.h>
15#include <sys/resource.h>
b67f7691 16.PP
0f8ac93b
KM
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
b67f7691 28.SH DESCRIPTION
0f8ac93b
KM
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
7345eeba 41the maximum amount of cpu time (in seconds) to be used by
0f8ac93b
KM
42each process.
43.TP 17
44RLIMIT_FSIZE
63b0bb9c 45the largest size, in bytes, of any single file that may be created.
0f8ac93b
KM
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
b67f7691 50.IR sbrk (2)
0f8ac93b
KM
51system call.
52.TP 17
53RLIMIT_STACK
54the maximum size, in bytes, of the stack segment for a process;
65d38ebd
MK
55this defines how far a program's stack segment may be extended.
56Stack extension is performed automatically by the system.
0f8ac93b
KM
57.TP 17
58RLIMIT_CORE
59the largest size, in bytes, of a
60.I core
63b0bb9c 61file that may be created.
0f8ac93b
KM
62.TP 17
63RLIMIT_RSS
65d38ebd
MK
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
0f8ac93b 66to be given to a process; if memory is tight, the system will
63b0bb9c 67prefer to take memory from processes that are exceeding their
0f8ac93b
KM
68declared resident set size.
69.PP
19a3a68f
KB
70A resource limit is specified as a soft limit and a hard limit. When a
71soft limit is exceeded a process may receive a signal (for example, if
72the cpu time or file size is exceeded), but it will be allowed to
73continue execution until it reaches the hard limit (or modifies
0f8ac93b
KM
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
7345eeba 96An \*(lqinfinite\*(rq value for a limit is defined as RLIM_INFINITY
0f8ac93b 97(0x7\&f\&f\&f\&f\&f\&f\&f).
b67f7691 98.PP
0f8ac93b 99Because this information is stored in the per-process information,
b67f7691
KM
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
0f8ac93b 107would be exceeded in the normal way: a
b67f7691 108.I break
65d38ebd
MK
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.
b67f7691 114.PP
19a3a68f
KB
115A file I/O operation that would create a file larger that the process'
116soft limit will cause the write to fail and a signal SIGXFSZ to be
117generated; this normally terminates the process, but may be caught. When
118the soft cpu time limit is exceeded, a signal SIGXCPU is sent to the
0f8ac93b
KM
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.
b67f7691 133.SH SEE ALSO
65d38ebd 134csh(1), quota(2), sigvec(2), sigstack(2)
b67f7691 135.SH BUGS
b67f7691
KM
136There should be
137.I limit
138and
139.I unlimit
140commands in
141.IR sh (1)
142as well as in
143.IR csh.