]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
1 | .\" $NetBSD: getrlimit.2,v 1.8 1995/10/12 15:40:58 jtc Exp $ |
2 | .\" | |
3 | .\" Copyright (c) 1980, 1991, 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. All advertising materials mentioning features or use of this software | |
15 | .\" must display the following acknowledgement: | |
16 | .\" This product includes software developed by the University of | |
17 | .\" California, Berkeley and its contributors. | |
18 | .\" 4. Neither the name of the University nor the names of its contributors | |
19 | .\" may be used to endorse or promote products derived from this software | |
20 | .\" without specific prior written permission. | |
21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93 | |
35 | .\" | |
36 | .Dd June 4, 1993 | |
37 | .Dt GETRLIMIT 2 | |
38 | .Os BSD 4 | |
39 | .Sh NAME | |
40 | .Nm getrlimit , | |
41 | .Nm setrlimit | |
42 | .Nd control maximum system resource consumption | |
43 | .Sh SYNOPSIS | |
44 | .Fd #include <sys/types.h> | |
45 | .Fd #include <sys/time.h> | |
46 | .Fd #include <sys/resource.h> | |
47 | .Ft int | |
48 | .Fn getrlimit "int resource" "struct rlimit *rlp" | |
49 | .Ft int | |
50 | .Fn setrlimit "int resource" "const struct rlimit *rlp" | |
51 | .Sh DESCRIPTION | |
52 | Limits on the consumption of system resources by the current process | |
53 | and each process it creates may be obtained with the | |
54 | .Fn getrlimit | |
55 | call, and set with the | |
56 | .Fn setrlimit | |
57 | call. | |
58 | .Pp | |
59 | The | |
60 | .Fa resource | |
61 | parameter is one of the following: | |
62 | .Bl -tag -width RLIMIT_FSIZEAA | |
63 | .It Li RLIMIT_CORE | |
64 | The largest size (in bytes) | |
65 | .Xr core | |
66 | file that may be created. | |
67 | .It Li RLIMIT_CPU | |
68 | The maximum amount of cpu time (in seconds) to be used by | |
69 | each process. | |
70 | .It Li RLIMIT_DATA | |
71 | The maximum size (in bytes) of the data segment for a process; | |
72 | this defines how far a program may extend its break with the | |
73 | .Xr sbrk 2 | |
74 | system call. | |
75 | .It Li RLIMIT_FSIZE | |
76 | The largest size (in bytes) file that may be created. | |
77 | .It Li RLIMIT_MEMLOCK | |
78 | The maximum size (in bytes) which a process may lock into memory | |
79 | using the | |
80 | .Xr mlock 2 | |
81 | function. | |
82 | .It Li RLIMIT_NOFILE | |
83 | The maximum number of open files for this process. | |
84 | .It Li RLIMIT_NPROC | |
85 | The maximum number of simultaneous processes for this user id. | |
86 | .It Li RLIMIT_RSS | |
87 | The maximum size (in bytes) to which a process's resident set size may | |
88 | grow. | |
89 | This imposes a limit on the amount of physical memory to be given to | |
90 | a process; if memory is tight, the system will prefer to take memory | |
91 | from processes that are exceeding their declared resident set size. | |
92 | .It Li RLIMIT_STACK | |
93 | The maximum size (in bytes) of the stack segment for a process; | |
94 | this defines how far a program's stack segment may be extended. | |
95 | Stack extension is performed automatically by the system. | |
96 | .El | |
97 | .Pp | |
98 | A resource limit is specified as a soft limit and a hard limit. When a | |
99 | soft limit is exceeded a process may receive a signal (for example, if | |
100 | the cpu time or file size is exceeded), but it will be allowed to | |
101 | continue execution until it reaches the hard limit (or modifies | |
102 | its resource limit). The | |
103 | .Em rlimit | |
104 | structure is used to specify the hard and soft limits on a resource, | |
105 | .Bd -literal -offset indent | |
106 | struct rlimit { | |
107 | rlim_t rlim_cur; /* current (soft) limit */ | |
108 | rlim_t rlim_max; /* hard limit */ | |
109 | }; | |
110 | .Ed | |
111 | .Pp | |
112 | Only the super-user may raise the maximum limits. Other users | |
113 | may only alter | |
114 | .Fa rlim_cur | |
115 | within the range from 0 to | |
116 | .Fa rlim_max | |
117 | or (irreversibly) lower | |
118 | .Fa rlim_max . | |
119 | .Pp | |
120 | An | |
121 | .Dq infinite | |
122 | value for a limit is defined as | |
123 | .Dv RLIM_INFINITY . | |
124 | .Pp | |
125 | Because this information is stored in the per-process information, | |
126 | this system call must be executed directly by the shell if it | |
127 | is to affect all future processes created by the shell; | |
128 | .Ic limit | |
129 | is thus a built-in command to | |
130 | .Xr csh 1 | |
131 | and | |
132 | .Ic ulimit | |
133 | is the | |
134 | .Xr sh 1 | |
135 | equivalent. | |
136 | .Pp | |
137 | The system refuses to extend the data or stack space when the limits | |
138 | would be exceeded in the normal way: a | |
139 | .Xr break | |
140 | call fails if the data space limit is reached. | |
141 | When the stack limit is reached, the process receives | |
142 | a segmentation fault | |
143 | .Pq Dv SIGSEGV ; | |
144 | if this signal is not | |
145 | caught by a handler using the signal stack, this signal | |
146 | will kill the process. | |
147 | .Pp | |
148 | A file I/O operation that would create a file larger that the process' | |
149 | soft limit will cause the write to fail and a signal | |
150 | .Dv SIGXFSZ | |
151 | to be | |
152 | generated; this normally terminates the process, but may be caught. When | |
153 | the soft cpu time limit is exceeded, a signal | |
154 | .Dv SIGXCPU | |
155 | is sent to the | |
156 | offending process. | |
157 | .Sh RETURN VALUES | |
158 | A 0 return value indicates that the call succeeded, changing | |
159 | or returning the resource limit. A return value of -1 indicates | |
160 | that an error occurred, and an error code is stored in the global | |
161 | location | |
162 | .Va errno . | |
163 | .Sh ERRORS | |
164 | .Fn Getrlimit | |
165 | and | |
166 | .Fn setrlimit | |
167 | will fail if: | |
168 | .Bl -tag -width Er | |
169 | .It Bq Er EFAULT | |
170 | The address specified for | |
171 | .Fa rlp | |
172 | is invalid. | |
173 | .It Bq Er EPERM | |
174 | The limit specified to | |
175 | .Fn setrlimit | |
176 | would have | |
177 | raised the maximum limit value, and the caller is not the super-user. | |
178 | .El | |
179 | .Sh SEE ALSO | |
180 | .Xr csh 1 , | |
181 | .Xr sh 1 , | |
182 | .Xr quota 2 , | |
183 | .Xr sigaction 2 , | |
184 | .Xr sigaltstack 2 , | |
185 | .Xr sysctl 3 | |
186 | .Sh HISTORY | |
187 | The | |
188 | .Fn getrlimit | |
189 | function call appeared in | |
190 | .Bx 4.2 . |