Commit | Line | Data |
---|---|---|
931b8415 | 1 | .\" Copyright (c) 1980, 1991 The Regents of the University of California. |
88b3ccf2 | 2 | .\" All rights reserved. |
b67f7691 | 3 | .\" |
af359dea C |
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. | |
88b3ccf2 | 19 | .\" |
af359dea C |
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. | |
b67f7691 | 31 | .\" |
af359dea C |
32 | .\" @(#)getrlimit.2 6.7 (Berkeley) 3/10/91 |
33 | .\" | |
34 | .Dd March 10, 1991 | |
931b8415 CL |
35 | .Dt GETRLIMIT 2 |
36 | .Os BSD 4 | |
37 | .Sh NAME | |
38 | .Nm getrlimit , | |
39 | .Nm setrlimit | |
40 | .Nd control maximum system resource consumption | |
41 | .Sh SYNOPSIS | |
42 | .Fd #include <sys/time.h> | |
43 | .Fd #include <sys/resource.h> | |
44 | .Ft int | |
45 | .Fn getrlimit "int resource" "struct rlimit *rlp" | |
46 | .Ft int | |
47 | .Fn setrlimit "int resource" "struct rlimit *rlp" | |
48 | .Sh DESCRIPTION | |
0f8ac93b KM |
49 | Limits on the consumption of system resources by the current process |
50 | and each process it creates may be obtained with the | |
931b8415 | 51 | .Fn getrlimit |
0f8ac93b | 52 | call, and set with the |
931b8415 | 53 | .Fn setrlimit |
0f8ac93b | 54 | call. |
931b8415 | 55 | .Pp |
0f8ac93b | 56 | The |
931b8415 | 57 | .Fa resource |
0f8ac93b | 58 | parameter is one of the following: |
931b8415 CL |
59 | .Bl -tag -width RLIMIT_FSIZEAA |
60 | .It Dv RLIMIT_CPU | |
7345eeba | 61 | the maximum amount of cpu time (in seconds) to be used by |
0f8ac93b | 62 | each process. |
931b8415 | 63 | .It Dv RLIMIT_FSIZE |
63b0bb9c | 64 | the largest size, in bytes, of any single file that may be created. |
931b8415 | 65 | .It Dv RLIMIT_DATA |
0f8ac93b KM |
66 | the maximum size, in bytes, of the data segment for a process; |
67 | this defines how far a program may extend its break with the | |
931b8415 | 68 | .Xr sbrk 2 |
0f8ac93b | 69 | system call. |
931b8415 | 70 | .It Dv RLIMIT_STACK |
0f8ac93b | 71 | the maximum size, in bytes, of the stack segment for a process; |
65d38ebd MK |
72 | this defines how far a program's stack segment may be extended. |
73 | Stack extension is performed automatically by the system. | |
931b8415 | 74 | .It Dv RLIMIT_CORE |
0f8ac93b | 75 | the largest size, in bytes, of a |
931b8415 | 76 | .Xr core |
63b0bb9c | 77 | file that may be created. |
931b8415 | 78 | .It Dv RLIMIT_RSS |
65d38ebd MK |
79 | the maximum size, in bytes, to which a process's resident set size may |
80 | grow. This imposes a limit on the amount of physical memory | |
0f8ac93b | 81 | to be given to a process; if memory is tight, the system will |
63b0bb9c | 82 | prefer to take memory from processes that are exceeding their |
0f8ac93b | 83 | declared resident set size. |
931b8415 CL |
84 | .El |
85 | .Pp | |
19a3a68f KB |
86 | A resource limit is specified as a soft limit and a hard limit. When a |
87 | soft limit is exceeded a process may receive a signal (for example, if | |
88 | the cpu time or file size is exceeded), but it will be allowed to | |
89 | continue execution until it reaches the hard limit (or modifies | |
0f8ac93b | 90 | its resource limit). The |
931b8415 | 91 | .Em rlimit |
0f8ac93b | 92 | structure is used to specify the hard and soft limits on a resource, |
931b8415 | 93 | .Bd -literal -offset indent |
0f8ac93b KM |
94 | struct rlimit { |
95 | int rlim_cur; /* current (soft) limit */ | |
96 | int rlim_max; /* hard limit */ | |
97 | }; | |
931b8415 CL |
98 | .Ed |
99 | .Pp | |
0f8ac93b KM |
100 | Only the super-user may raise the maximum limits. Other users |
101 | may only alter | |
931b8415 | 102 | .Fa rlim_cur |
0f8ac93b | 103 | within the range from 0 to |
931b8415 | 104 | .Fa rlim_max |
0f8ac93b | 105 | or (irreversibly) lower |
931b8415 CL |
106 | .Fa rlim_max . |
107 | .Pp | |
108 | An | |
109 | .Dq infinite | |
110 | value for a limit is defined as | |
111 | .Dv RLIM_INFINITY | |
0f8ac93b | 112 | (0x7\&f\&f\&f\&f\&f\&f\&f). |
931b8415 | 113 | .Pp |
0f8ac93b | 114 | Because this information is stored in the per-process information, |
b67f7691 KM |
115 | this system call must be executed directly by the shell if it |
116 | is to affect all future processes created by the shell; | |
931b8415 | 117 | .Ic limit |
b67f7691 | 118 | is thus a built-in command to |
931b8415 CL |
119 | .Xr csh 1 . |
120 | .Pp | |
b67f7691 | 121 | The system refuses to extend the data or stack space when the limits |
0f8ac93b | 122 | would be exceeded in the normal way: a |
931b8415 | 123 | .Xr break |
65d38ebd MK |
124 | call fails if the data space limit is reached. |
125 | When the stack limit is reached, the process receives | |
931b8415 CL |
126 | a segmentation fault |
127 | .Pq Dv SIGSEGV ; | |
128 | if this signal is not | |
65d38ebd MK |
129 | caught by a handler using the signal stack, this signal |
130 | will kill the process. | |
931b8415 | 131 | .Pp |
19a3a68f | 132 | A file I/O operation that would create a file larger that the process' |
931b8415 CL |
133 | soft limit will cause the write to fail and a signal |
134 | .Dv SIGXFSZ | |
135 | to be | |
19a3a68f | 136 | generated; this normally terminates the process, but may be caught. When |
931b8415 CL |
137 | the soft cpu time limit is exceeded, a signal |
138 | .Dv SIGXCPU | |
139 | is sent to the | |
0f8ac93b | 140 | offending process. |
931b8415 | 141 | .Sh RETURN VALUES |
0f8ac93b | 142 | A 0 return value indicates that the call succeeded, changing |
931b8415 | 143 | or returning the resource limit. A return value of -1 indicates |
0f8ac93b | 144 | that an error occurred, and an error code is stored in the global |
931b8415 CL |
145 | location |
146 | .Va errno . | |
147 | .Sh ERRORS | |
148 | .Fn Getrlimit | |
149 | and | |
150 | .Fn setrlimit | |
151 | will fail if: | |
152 | .Bl -tag -width Er | |
153 | .It Bq Er EFAULT | |
154 | The address specified for | |
155 | .Fa rlp | |
156 | is invalid. | |
157 | .It Bq Er EPERM | |
158 | The limit specified to | |
159 | .Fn setrlimit | |
160 | would have | |
0f8ac93b | 161 | raised the maximum limit value, and the caller is not the super-user. |
931b8415 CL |
162 | .El |
163 | .Sh SEE ALSO | |
164 | .Xr csh 1 , | |
165 | .Xr quota 2 , | |
166 | .Xr sigvec 2 , | |
167 | .Xr sigstack 2 | |
168 | .Sh BUGS | |
b67f7691 | 169 | There should be |
931b8415 | 170 | .Ic limit |
b67f7691 | 171 | and |
931b8415 | 172 | .Ic unlimit |
b67f7691 | 173 | commands in |
931b8415 | 174 | .Xr sh 1 |
b67f7691 | 175 | as well as in |
931b8415 CL |
176 | .Xr csh . |
177 | .Sh HISTORY | |
178 | The | |
179 | .Nm | |
180 | function call appeared in | |
181 | .Bx 4.2 . |