Improved english
[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.\"
7345eeba 5.\" @(#)getrlimit.2 6.1 (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
45the largest size, in bytes, of any single file which 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
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;
55this defines how far a program's stack segment may be extended,
56either automatically by the system, or explicitly by a user with
57the
58.IR sbrk (2)
59system call.
60.TP 17
61RLIMIT_CORE
62the largest size, in bytes, of a
63.I core
64file which may be created.
65.TP 17
66RLIMIT_RSS
67the maximum size, in bytes, a process's resident set size may
68grow to. This imposes a limit on the amount of physical memory
69to be given to a process; if memory is tight, the system will
70prefer to take memory from processes which are exceeding their
71declared resident set size.
72.PP
73A resource limit is specified as a soft limit and a hard limit.
74When a soft limit is exceeded a process may receive a signal
75(for example, if the cpu time is exceeded), but it will be allowed
76to continue execution until it reaches the hard limit (or modifies
77its resource limit). The
78.I rlimit
79structure is used to specify the hard and soft limits on a resource,
80.PP
81.nf
82.RS
83.DT
84struct rlimit {
85 int rlim_cur; /* current (soft) limit */
86 int rlim_max; /* hard limit */
87};
88.RE
89.fi
90.PP
91Only the super-user may raise the maximum limits. Other users
92may only alter
93.I rlim_cur
94within the range from 0 to
95.I rlim_max
96or (irreversibly) lower
97.IR rlim_max .
98.PP
7345eeba 99An \*(lqinfinite\*(rq value for a limit is defined as RLIM_INFINITY
0f8ac93b 100(0x7\&f\&f\&f\&f\&f\&f\&f).
b67f7691 101.PP
0f8ac93b 102Because this information is stored in the per-process information,
b67f7691
KM
103this system call must be executed directly by the shell if it
104is to affect all future processes created by the shell;
105.I limit
106is thus a built-in command to
107.IR csh (1).
108.PP
109The system refuses to extend the data or stack space when the limits
0f8ac93b 110would be exceeded in the normal way: a
b67f7691
KM
111.I break
112call fails if the data space limit is reached, or the process is
113killed when the stack limit is reached (since the stack cannot be
114extended, there is no way to send a signal!).
115.PP
116A file i/o operation which would create a file which is too large
117will cause a signal SIGXFSZ to be generated, this normally terminates
118the process, but may be caught.
0f8ac93b
KM
119When the soft cpu time limit is exceeded, a signal SIGXCPU is sent to the
120offending process.
121.SH "RETURN VALUE
122A 0 return value indicates that the call succeeded, changing
123or returning the resource limit. A return value of \-1 indicates
124that an error occurred, and an error code is stored in the global
125location \fIerrno\fP.
126.SH "ERRORS
127The possible errors are:
128.TP 15
129[EFAULT]
130The address specified for \fIrlp\fP is invalid.
131.TP 15
132[EPERM] The limit specified to \fIsetrlimit\fP would have
133raised the maximum limit value, and the caller is not the super-user.
b67f7691 134.SH SEE ALSO
0f8ac93b 135csh(1), quota(2)
b67f7691 136.SH BUGS
b67f7691
KM
137There should be
138.I limit
139and
140.I unlimit
141commands in
142.IR sh (1)
143as well as in
144.IR csh.