1GETRLIMIT(3P) POSIX Programmer's Manual GETRLIMIT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 getrlimit, setrlimit - control maximum resource consumption
13
15 #include <sys/resource.h>
16
17 int getrlimit(int resource, struct rlimit *rlp);
18 int setrlimit(int resource, const struct rlimit *rlp);
19
20
22 The getrlimit() function shall get, and the setrlimit() function shall
23 set, limits on the consumption of a variety of resources.
24
25 Each call to either getrlimit() or setrlimit() identifies a specific
26 resource to be operated upon as well as a resource limit. A resource
27 limit is represented by an rlimit structure. The rlim_cur member speci‐
28 fies the current or soft limit and the rlim_max member specifies the
29 maximum or hard limit. Soft limits may be changed by a process to any
30 value that is less than or equal to the hard limit. A process may
31 (irreversibly) lower its hard limit to any value that is greater than
32 or equal to the soft limit. Only a process with appropriate privileges
33 can raise a hard limit. Both hard and soft limits can be changed in a
34 single call to setrlimit() subject to the constraints described above.
35
36 The value RLIM_INFINITY, defined in <sys/resource.h>, shall be consid‐
37 ered to be larger than any other limit value. If a call to getrlimit()
38 returns RLIM_INFINITY for a resource, it means the implementation shall
39 not enforce limits on that resource. Specifying RLIM_INFINITY as any
40 resource limit value on a successful call to setrlimit() shall inhibit
41 enforcement of that resource limit.
42
43 The following resources are defined:
44
45 RLIMIT_CORE
46 This is the maximum size of a core file, in bytes, that may be
47 created by a process. A limit of 0 shall prevent the creation of
48 a core file. If this limit is exceeded, the writing of a core
49 file shall terminate at this size.
50
51 RLIMIT_CPU
52 This is the maximum amount of CPU time, in seconds, used by a
53 process. If this limit is exceeded, SIGXCPU shall be generated
54 for the process. If the process is catching or ignoring SIGXCPU,
55 or all threads belonging to that process are blocking SIGXCPU,
56 the behavior is unspecified.
57
58 RLIMIT_DATA
59 This is the maximum size of a process' data segment, in bytes.
60 If this limit is exceeded, the malloc() function shall fail with
61 errno set to [ENOMEM].
62
63 RLIMIT_FSIZE
64 This is the maximum size of a file, in bytes, that may be cre‐
65 ated by a process. If a write or truncate operation would cause
66 this limit to be exceeded, SIGXFSZ shall be generated for the
67 thread. If the thread is blocking, or the process is catching
68 or ignoring SIGXFSZ, continued attempts to increase the size of
69 a file from end-of-file to beyond the limit shall fail with
70 errno set to [EFBIG].
71
72 RLIMIT_NOFILE
73 This is a number one greater than the maximum value that the
74 system may assign to a newly-created descriptor. If this limit
75 is exceeded, functions that allocate a file descriptor shall
76 fail with errno set to [EMFILE]. This limit constrains the num‐
77 ber of file descriptors that a process may allocate.
78
79 RLIMIT_STACK
80 This is the maximum size of a process' stack, in bytes. The
81 implementation does not automatically grow the stack beyond this
82 limit. If this limit is exceeded, SIGSEGV shall be generated for
83 the thread. If the thread is blocking SIGSEGV, or the process is
84 ignoring or catching SIGSEGV and has not made arrangements to
85 use an alternate stack, the disposition of SIGSEGV shall be set
86 to SIG_DFL before it is generated.
87
88 RLIMIT_AS
89 This is the maximum size of a process' total available memory,
90 in bytes. If this limit is exceeded, the malloc() and mmap()
91 functions shall fail with errno set to [ENOMEM]. In addition,
92 the automatic stack growth fails with the effects outlined
93 above.
94
95
96 When using the getrlimit() function, if a resource limit can be repre‐
97 sented correctly in an object of type rlim_t, then its representation
98 is returned; otherwise, if the value of the resource limit is equal to
99 that of the corresponding saved hard limit, the value returned shall be
100 RLIM_SAVED_MAX; otherwise, the value returned shall be RLIM_SAVED_CUR.
101
102 When using the setrlimit() function, if the requested new limit is
103 RLIM_INFINITY, the new limit shall be "no limit''; otherwise, if the
104 requested new limit is RLIM_SAVED_MAX, the new limit shall be the cor‐
105 responding saved hard limit; otherwise, if the requested new limit is
106 RLIM_SAVED_CUR, the new limit shall be the corresponding saved soft
107 limit; otherwise, the new limit shall be the requested value. In addi‐
108 tion, if the corresponding saved limit can be represented correctly in
109 an object of type rlim_t then it shall be overwritten with the new
110 limit.
111
112 The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
113 unspecified unless a previous call to getrlimit() returned that value
114 as the soft or hard limit for the corresponding resource limit.
115
116 The determination of whether a limit can be correctly represented in an
117 object of type rlim_t is implementation-defined. For example, some
118 implementations permit a limit whose value is greater than RLIM_INFIN‐
119 ITY and others do not.
120
121 The exec family of functions shall cause resource limits to be saved.
122
124 Upon successful completion, getrlimit() and setrlimit() shall return 0.
125 Otherwise, these functions shall return -1 and set errno to indicate
126 the error.
127
129 The getrlimit() and setrlimit() functions shall fail if:
130
131 EINVAL An invalid resource was specified; or in a setrlimit() call, the
132 new rlim_cur exceeds the new rlim_max.
133
134 EPERM The limit specified to setrlimit() would have raised the maximum
135 limit value, and the calling process does not have appropriate
136 privileges.
137
138
139 The setrlimit() function may fail if:
140
141 EINVAL The limit specified cannot be lowered because current usage is
142 already higher than the limit.
143
144
145 The following sections are informative.
146
148 None.
149
151 If a process attempts to set the hard limit or soft limit for
152 RLIMIT_NOFILE to less than the value of {_POSIX_OPEN_MAX} from <lim‐
153 its.h>, unexpected behavior may occur.
154
155 If a process attempts to set the hard limit or soft limit for
156 RLIMIT_NOFILE to less than the highest currently open file descriptor
157 +1, unexpected behavior may occur.
158
160 None.
161
163 None.
164
166 exec(), fork(), malloc(), open(), sigaltstack() , sysconf(), ulimit(),
167 the Base Definitions volume of IEEE Std 1003.1-2001, <stropts.h>,
168 <sys/resource.h>
169
171 Portions of this text are reprinted and reproduced in electronic form
172 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
173 -- Portable Operating System Interface (POSIX), The Open Group Base
174 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
175 Electrical and Electronics Engineers, Inc and The Open Group. In the
176 event of any discrepancy between this version and the original IEEE and
177 The Open Group Standard, the original IEEE and The Open Group Standard
178 is the referee document. The original Standard can be obtained online
179 at http://www.opengroup.org/unix/online.html .
180
181
182
183IEEE/The Open Group 2003 GETRLIMIT(3P)