Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | .\" Copyright (c) 1980, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
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. | |
19 | .\" | |
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. | |
31 | .\" | |
32 | .\" @(#)getrlimit.2 6.7 (Berkeley) 3/10/91 | |
33 | .\" | |
34 | .Dd March 10, 1991 | |
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 | |
49 | Limits on the consumption of system resources by the current process | |
50 | and each process it creates may be obtained with the | |
51 | .Fn getrlimit | |
52 | call, and set with the | |
53 | .Fn setrlimit | |
54 | call. | |
55 | .Pp | |
56 | The | |
57 | .Fa resource | |
58 | parameter is one of the following: | |
59 | .Bl -tag -width RLIMIT_FSIZEAA | |
60 | .It Dv RLIMIT_CPU | |
61 | the maximum amount of cpu time (in seconds) to be used by | |
62 | each process. | |
63 | .It Dv RLIMIT_FSIZE | |
64 | the largest size, in bytes, of any single file that may be created. | |
65 | .It Dv RLIMIT_DATA | |
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 | |
68 | .Xr sbrk 2 | |
69 | system call. | |
70 | .It Dv RLIMIT_STACK | |
71 | the maximum size, in bytes, of the stack segment for a process; | |
72 | this defines how far a program's stack segment may be extended. | |
73 | Stack extension is performed automatically by the system. | |
74 | .It Dv RLIMIT_CORE | |
75 | the largest size, in bytes, of a | |
76 | .Xr core | |
77 | file that may be created. | |
78 | .It Dv RLIMIT_RSS | |
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 | |
81 | to be given to a process; if memory is tight, the system will | |
82 | prefer to take memory from processes that are exceeding their | |
83 | declared resident set size. | |
84 | .El | |
85 | .Pp | |
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 | |
90 | its resource limit). The | |
91 | .Em rlimit | |
92 | structure is used to specify the hard and soft limits on a resource, | |
93 | .Bd -literal -offset indent | |
94 | struct rlimit { | |
95 | int rlim_cur; /* current (soft) limit */ | |
96 | int rlim_max; /* hard limit */ | |
97 | }; | |
98 | .Ed | |
99 | .Pp | |
100 | Only the super-user may raise the maximum limits. Other users | |
101 | may only alter | |
102 | .Fa rlim_cur | |
103 | within the range from 0 to | |
104 | .Fa rlim_max | |
105 | or (irreversibly) lower | |
106 | .Fa rlim_max . | |
107 | .Pp | |
108 | An | |
109 | .Dq infinite | |
110 | value for a limit is defined as | |
111 | .Dv RLIM_INFINITY | |
112 | (0x7\&f\&f\&f\&f\&f\&f\&f). | |
113 | .Pp | |
114 | Because this information is stored in the per-process information, | |
115 | this system call must be executed directly by the shell if it | |
116 | is to affect all future processes created by the shell; | |
117 | .Ic limit | |
118 | is thus a built-in command to | |
119 | .Xr csh 1 . | |
120 | .Pp | |
121 | The system refuses to extend the data or stack space when the limits | |
122 | would be exceeded in the normal way: a | |
123 | .Xr break | |
124 | call fails if the data space limit is reached. | |
125 | When the stack limit is reached, the process receives | |
126 | a segmentation fault | |
127 | .Pq Dv SIGSEGV ; | |
128 | if this signal is not | |
129 | caught by a handler using the signal stack, this signal | |
130 | will kill the process. | |
131 | .Pp | |
132 | A file I/O operation that would create a file larger that the process' | |
133 | soft limit will cause the write to fail and a signal | |
134 | .Dv SIGXFSZ | |
135 | to be | |
136 | generated; this normally terminates the process, but may be caught. When | |
137 | the soft cpu time limit is exceeded, a signal | |
138 | .Dv SIGXCPU | |
139 | is sent to the | |
140 | offending process. | |
141 | .Sh RETURN VALUES | |
142 | A 0 return value indicates that the call succeeded, changing | |
143 | or returning the resource limit. A return value of -1 indicates | |
144 | that an error occurred, and an error code is stored in the global | |
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 | |
161 | raised the maximum limit value, and the caller is not the super-user. | |
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 | |
169 | There should be | |
170 | .Ic limit | |
171 | and | |
172 | .Ic unlimit | |
173 | commands in | |
174 | .Xr sh 1 | |
175 | as well as in | |
176 | .Xr csh . | |
177 | .Sh HISTORY | |
178 | The | |
179 | .Nm | |
180 | function call appeared in | |
181 | .Bx 4.2 . |