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