1GETRLIMIT(3P)              POSIX Programmer's Manual             GETRLIMIT(3P)
2
3
4

PROLOG

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
11

NAME

13       getrlimit, setrlimit — control maximum resource consumption
14

SYNOPSIS

16       #include <sys/resource.h>
17
18       int getrlimit(int resource, struct rlimit *rlp);
19       int setrlimit(int resource, const struct rlimit *rlp);
20

DESCRIPTION

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   This  is  the maximum size of a core file, in bytes, that
46                     may be created by a process. A limit of 0  shall  prevent
47                     the  creation  of a core file. If this limit is exceeded,
48                     the writing of a core file shall terminate at this size.
49
50       RLIMIT_CPU    This is the maximum amount of CPU time, in seconds,  used
51                     by  a  process.  If this limit is exceeded, SIGXCPU shall
52                     be generated for the process. If the process is  catching
53                     or  ignoring  SIGXCPU,  or  all threads belonging to that
54                     process are blocking SIGXCPU, the  behavior  is  unspeci‐
55                     fied.
56
57       RLIMIT_DATA   This  is  the  maximum  size  of  a  data  segment of the
58                     process, in bytes.  If this limit is exceeded,  the  mal‐
59                     loc() function shall fail with errno set to [ENOMEM].
60
61       RLIMIT_FSIZE  This is the maximum size of a file, in bytes, that may be
62                     created by a process. If a write  or  truncate  operation
63                     would  cause  this limit to be exceeded, SIGXFSZ shall be
64                     generated for the thread. If the thread is  blocking,  or
65                     the  process  is  catching or ignoring SIGXFSZ, continued
66                     attempts to increase the size of a file from  end-of-file
67                     to beyond the limit shall fail with errno set to [EFBIG].
68
69       RLIMIT_NOFILE This  is a number one greater than the maximum value that
70                     the system may assign to a newly-created  descriptor.  If
71                     this  limit  is  exceeded, functions that allocate a file
72                     descriptor shall fail with errno set to  [EMFILE].   This
73                     limit  constrains  the  number of file descriptors that a
74                     process may allocate.
75
76       RLIMIT_STACK  This is the maximum size of the initial  thread's  stack,
77                     in  bytes. The implementation does not automatically grow
78                     the stack beyond this limit. If this limit  is  exceeded,
79                     SIGSEGV  shall be generated for the thread. If the thread
80                     is blocking SIGSEGV, or the process is ignoring or catch‐
81                     ing  SIGSEGV  and  has  not  made  arrangements to use an
82                     alternate stack, the disposition of SIGSEGV shall be  set
83                     to SIG_DFL before it is generated.
84
85       RLIMIT_AS     This is the maximum size of total available memory of the
86                     process, in bytes. If this limit is  exceeded,  the  mal‐
87                     loc()  and  mmap() functions shall fail with errno set to
88                     [ENOMEM].  In addition, the automatic stack growth  fails
89                     with the effects outlined above.
90
91       When  using the getrlimit() function, if a resource limit can be repre‐
92       sented correctly in an object of type rlim_t, then  its  representation
93       is  returned; otherwise, if the value of the resource limit is equal to
94       that of the corresponding saved hard limit, the value returned shall be
95       RLIM_SAVED_MAX; otherwise, the value returned shall be RLIM_SAVED_CUR.
96
97       When  using  the  setrlimit()  function,  if the requested new limit is
98       RLIM_INFINITY, the new limit shall be ``no limit''; otherwise,  if  the
99       requested  new limit is RLIM_SAVED_MAX, the new limit shall be the cor‐
100       responding saved hard limit; otherwise, if the requested new  limit  is
101       RLIM_SAVED_CUR,  the  new  limit  shall be the corresponding saved soft
102       limit; otherwise, the new limit shall be the requested value. In  addi‐
103       tion,  if the corresponding saved limit can be represented correctly in
104       an object of type rlim_t then it shall  be  overwritten  with  the  new
105       limit.
106
107       The  result  of  setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
108       unspecified unless a previous call to getrlimit() returned  that  value
109       as the soft or hard limit for the corresponding resource limit.
110
111       The determination of whether a limit can be correctly represented in an
112       object of type rlim_t  is  implementation-defined.  For  example,  some
113       implementations  permit a limit whose value is greater than RLIM_INFIN‐
114       ITY and others do not.
115
116       The exec family of functions shall cause resource limits to be saved.
117

RETURN VALUE

119       Upon successful completion, getrlimit() and setrlimit() shall return 0.
120       Otherwise,  these  functions  shall return −1 and set errno to indicate
121       the error.
122

ERRORS

124       The getrlimit() and setrlimit() functions shall fail if:
125
126       EINVAL An invalid resource was specified; or in a setrlimit() call, the
127              new rlim_cur exceeds the new rlim_max.
128
129       EPERM  The limit specified to setrlimit() would have raised the maximum
130              limit value, and the calling process does not  have  appropriate
131              privileges.
132
133       The setrlimit() function may fail if:
134
135       EINVAL The  limit  specified cannot be lowered because current usage is
136              already higher than the limit.
137
138       The following sections are informative.
139

EXAMPLES

141       None.
142

APPLICATION USAGE

144       If a process  attempts  to  set  the  hard  limit  or  soft  limit  for
145       RLIMIT_NOFILE  to  less  than the value of {_POSIX_OPEN_MAX} from <lim‐
146       its.h>, unexpected behavior may occur.
147
148       If a process  attempts  to  set  the  hard  limit  or  soft  limit  for
149       RLIMIT_NOFILE  to  less than the highest currently open file descriptor
150       +1, unexpected behavior may occur.
151

RATIONALE

153       It should be noted that RLIMIT_STACK applies ``at least'' to the  stack
154       of  the  initial  thread  in the process, and not to the sum of all the
155       stacks in the process, as that would be very limiting unless the  value
156       is so big as to provide no value at all with a single thread.
157

FUTURE DIRECTIONS

159       None.
160

SEE ALSO

162       exec, fork(), malloc(), open(), sigaltstack(), sysconf(), ulimit()
163
164       The    Base    Definitions   volume   of   POSIX.1‐2008,   <stropts.h>,
165       <sys_resource.h>
166
168       Portions of this text are reprinted and reproduced in  electronic  form
169       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
170       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
171       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
172       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
173       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
174       event of any discrepancy between this version and the original IEEE and
175       The  Open Group Standard, the original IEEE and The Open Group Standard
176       is the referee document. The original Standard can be  obtained  online
177       at http://www.unix.org/online.html .
178
179       Any  typographical  or  formatting  errors that appear in this page are
180       most likely to have been introduced during the conversion of the source
181       files  to  man page format. To report such errors, see https://www.ker
182       nel.org/doc/man-pages/reporting_bugs.html .
183
184
185
186IEEE/The Open Group                  2013                        GETRLIMIT(3P)
Impressum