1getrlimit(2) System Calls getrlimit(2)
2
3
4
6 getrlimit, setrlimit - control maximum system resource consumption
7
9 #include <sys/resource.h>
10
11 int getrlimit(int resource, struct rlimit *rlp);
12
13
14 int setrlimit(int resource, const struct rlimit *rlp);
15
16
18 Limits on the consumption of a variety of system resources by a process
19 and each process it creates may be obtained with the getrlimit() and
20 set with setrlimit() functions.
21
22
23 Each call to either getrlimit() or setrlimit() identifies a specific
24 resource to be operated upon as well as a resource limit. A resource
25 limit is a pair of values: one specifying the current (soft) limit,
26 the other a maximum (hard) limit. Soft limits may be changed by a
27 process to any value that is less than or equal to the hard limit. A
28 process may (irreversibly) lower its hard limit to any value that is
29 greater than or equal to the soft limit. Only a process with
30 {PRIV_SYS_RESOURCE} asserted in the effective set can raise a hard
31 limit. Both hard and soft limits can be changed in a single call to
32 setrlimit() subject to the constraints described above. Limits may have
33 an "infinite" value of RLIM_INFINITY. The rlp argument is a pointer to
34 struct rlimit that includes the following members:
35
36 rlim_t rlim_cur; /* current (soft) limit */
37 rlim_t rlim_max; /* hard limit */
38
39
40
41 The type rlim_t is an arithmetic data type to which objects of type
42 int, size_t, and off_t can be cast without loss of information.
43
44
45 The possible resources, their descriptions, and the actions taken when
46 the current limit is exceeded are summarized as follows:
47
48 RLIMIT_CORE The maximum size of a core file in bytes that may be
49 created by a process. A limit of 0 will prevent the
50 creation of a core file. The writing of a core file
51 will terminate at this size.
52
53
54 RLIMIT_CPU The maximum amount of CPU time in seconds used by a
55 process. This is a soft limit only. The SIGXCPU sig‐
56 nal is sent to the process. If the process is holding
57 or ignoring SIGXCPU, the behavior is scheduling class
58 defined.
59
60
61 RLIMIT_DATA The maximum size of a process's heap in bytes. The
62 brk(2) function will fail with errno set to ENOMEM.
63
64
65 RLIMIT_FSIZE The maximum size of a file in bytes that may be cre‐
66 ated by a process. A limit of 0 will prevent the cre‐
67 ation of a file. The SIGXFSZ signal is sent to the
68 process. If the process is holding or ignoring
69 SIGXFSZ, continued attempts to increase the size of a
70 file beyond the limit will fail with errno set to
71 EFBIG.
72
73
74 RLIMIT_NOFILE One more than the maximum value that the system may
75 assign to a newly created descriptor. This limit con‐
76 strains the number of file descriptors that a process
77 may create.
78
79
80 RLIMIT_STACK The maximum size of a process's stack in bytes. The
81 system will not automatically grow the stack beyond
82 this limit.
83
84 Within a process, setrlimit() will increase the limit
85 on the size of your stack, but will not move current
86 memory segments to allow for that growth. To guarantee
87 that the process stack can grow to the limit, the
88 limit must be altered prior to the execution of the
89 process in which the new stack size is to be used.
90
91 Within a multithreaded process, setrlimit() has no
92 impact on the stack size limit for the calling thread
93 if the calling thread is not the main thread. A call
94 to setrlimit() for RLIMIT_STACK impacts only the main
95 thread's stack, and should be made only from the main
96 thread, if at all.
97
98 The SIGSEGV signal is sent to the process. If the
99 process is holding or ignoring SIGSEGV, or is catch‐
100 ing SIGSEGV and has not made arrangements to use an
101 alternate stack (see sigaltstack(2)), the disposition
102 of SIGSEGV will be set to SIG_DFL before it is sent.
103
104
105 RLIMIT_VMEM The maximum size of a process's mapped address space
106 in bytes. If this limit is exceeded, the brk(2) and
107 mmap(2) functions will fail with errno set to
108 ENOMEM. In addition, the automatic stack growth will
109 fail with the effects outlined above.
110
111
112 RLIMIT_AS This is the maximum size of a process's total avail‐
113 able memory, in bytes. If this limit is exceeded, the
114 brk(2), malloc(3C), mmap(2) and sbrk(2) functions will
115 fail with errno set to ENOMEM. In addition, the auto‐
116 matic stack growth will fail with the effects outlined
117 above.
118
119
120
121 Because limit information is stored in the per-process information, the
122 shell builtin ulimit command must directly execute this system call if
123 it is to affect all future processes created by the shell.
124
125
126 The value of the current limit of the following resources affect these
127 implementation defined parameters:
128
129
130
131
132 Limit Implementation Defined Constant
133 RLIMIT_FSIZE FCHR_MAX
134
135 RLIMIT_NOFILE OPEN_MAX
136
137
138
139 When using the getrlimit() function, if a resource limit can be repre‐
140 sented correctly in an object of type rlim_t, then its representation
141 is returned; otherwise, if the value of the resource limit is equal to
142 that of the corresponding saved hard limit, the value returned is
143 RLIM_SAVED_MAX; otherwise the value returned is RLIM_SAVED_CUR.
144
145
146 When using the setrlimit() function, if the requested new limit is
147 RLIM_INFINITY, the new limit will be "no limit"; otherwise if the
148 requested new limit is RLIM_SAVED_MAX, the new limit will be the corre‐
149 sponding saved hard limit; otherwise, if the requested new limit is
150 RLIM_SAVED_CUR, the new limit will be the corresponding saved soft
151 limit; otherwise, the new limit will be the requested value. In addi‐
152 tion, if the corresponding saved limit can be represented correctly in
153 an object of type rlim_t, then it will be overwritten with the new
154 limit.
155
156
157 The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
158 unspecified unless a previous call to getrlimit() returned that value
159 as the soft or hard limit for the corresponding resource limit.
160
161
162 A limit whose value is greater than RLIM_INFINITY is permitted.
163
164
165 The exec family of functions also cause resource limits to be saved.
166 See exec(2).
167
169 Upon successful completion, getrlimit() and setrlimit() return 0. Oth‐
170 erwise, these functions return −1 and set errno to indicate the error.
171
173 The getrlimit() and setrlimit() functions will fail if:
174
175 EFAULT The rlp argument points to an illegal address.
176
177
178 EINVAL An invalid resource was specified; or in a setrlimit() call,
179 the new rlim_cur exceeds the new rlim_max.
180
181
182 EPERM The limit specified to setrlimit() would have raised the max‐
183 imum limit value and {PRIV_SYS_RESOURCE} is not asserted in
184 the effective set of the current process.
185
186
187
188 The setrlimit() function may fail if:
189
190 EINVAL The limit specified cannot be lowered because current usage
191 is already higher than the limit.
192
193
195 The getrlimit() and setrlimit() functions have transitional interfaces
196 for 64-bit file offsets. See lf64(5).
197
198
199 The rlimit functionality is now provided by the more general resource
200 control facility described on the setrctl(2) manual page. The actions
201 associated with the resource limits described above are true at system
202 boot, but an administrator can modify the local configuration to modify
203 signal delivery or type. Application authors that utilize rlimits for
204 the purposes of resource awareness should investigate the resource con‐
205 trols facility.
206
208 See attributes(5) for descriptions of the following attributes:
209
210
211
212
213 ┌─────────────────────────────┬─────────────────────────────┐
214 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
215 ├─────────────────────────────┼─────────────────────────────┤
216 │Interface Stability │Standard │
217 └─────────────────────────────┴─────────────────────────────┘
218
220 rctladm(1M), brk(2), exec(2), fork(2), open(2), setrctl(2), sigalt‐
221 stack(2), ulimit(2), getdtablesize(3C), malloc(3C), signal(3C), sig‐
222 nal.h(3HEAD), sysconf(3C), attributes(5), lf64(5), privileges(5),
223 resource_controls(5), standards(5)
224
225
226
227SunOS 5.11 21 Aug 2006 getrlimit(2)