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

NAME

12       getrlimit, setrlimit — control maximum resource consumption
13

SYNOPSIS

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

DESCRIPTION

21       The getrlimit() function shall get, and the setrlimit() function  shall
22       set, limits on the consumption of a variety of resources.
23
24       Each  call  to  either getrlimit() or setrlimit() identifies a specific
25       resource to be operated upon as well as a resource  limit.  A  resource
26       limit is represented by an rlimit structure. The rlim_cur member speci‐
27       fies the current or soft limit and the rlim_max  member  specifies  the
28       maximum  or  hard limit. Soft limits may be changed by a process to any
29       value that is less than or equal to  the  hard  limit.  A  process  may
30       (irreversibly)  lower  its hard limit to any value that is greater than
31       or equal to the soft limit. Only a process with appropriate  privileges
32       can  raise  a hard limit. Both hard and soft limits can be changed in a
33       single call to setrlimit() subject to the constraints described above.
34
35       The value RLIM_INFINITY, defined in <sys/resource.h>, shall be  consid‐
36       ered  to be larger than any other limit value. If a call to getrlimit()
37       returns RLIM_INFINITY for a resource, it means the implementation shall
38       not  enforce  limits  on that resource. Specifying RLIM_INFINITY as any
39       resource limit value on a successful call to setrlimit() shall  inhibit
40       enforcement of that resource limit.
41
42       The following resources are defined:
43
44       RLIMIT_CORE   This  is  the maximum size of a core file, in bytes, that
45                     may be created by a process. A limit of 0  shall  prevent
46                     the  creation  of a core file. If this limit is exceeded,
47                     the writing of a core file shall terminate at this size.
48
49       RLIMIT_CPU    This is the maximum amount of CPU time, in seconds,  used
50                     by  a  process.  If this limit is exceeded, SIGXCPU shall
51                     be generated for the process. If the process is  catching
52                     or  ignoring  SIGXCPU,  or  all threads belonging to that
53                     process are blocking SIGXCPU, the  behavior  is  unspeci‐
54                     fied.
55
56       RLIMIT_DATA   This  is  the  maximum  size  of  a  data  segment of the
57                     process, in bytes.  If this limit is exceeded,  the  mal‐
58                     loc() function shall fail with errno set to [ENOMEM].
59
60       RLIMIT_FSIZE  This is the maximum size of a file, in bytes, that may be
61                     created by a process. If a write  or  truncate  operation
62                     would  cause  this limit to be exceeded, SIGXFSZ shall be
63                     generated for the thread. If the thread is  blocking,  or
64                     the  process  is  catching or ignoring SIGXFSZ, continued
65                     attempts to increase the size of a file from  end-of-file
66                     to beyond the limit shall fail with errno set to [EFBIG].
67
68       RLIMIT_NOFILE This  is a number one greater than the maximum value that
69                     the system may assign to a newly-created  descriptor.  If
70                     this  limit  is  exceeded, functions that allocate a file
71                     descriptor shall fail with errno set to  [EMFILE].   This
72                     limit  constrains  the  number of file descriptors that a
73                     process may allocate.
74
75       RLIMIT_STACK  This is the maximum size of the initial  thread's  stack,
76                     in  bytes. The implementation does not automatically grow
77                     the stack beyond this limit. If this limit  is  exceeded,
78                     SIGSEGV  shall be generated for the thread. If the thread
79                     is blocking SIGSEGV, or the process is ignoring or catch‐
80                     ing  SIGSEGV  and  has  not  made  arrangements to use an
81                     alternate stack, the disposition of SIGSEGV shall be  set
82                     to SIG_DFL before it is generated.
83
84       RLIMIT_AS     This is the maximum size of total available memory of the
85                     process, in bytes. If this limit is  exceeded,  the  mal‐
86                     loc()  and  mmap() functions shall fail with errno set to
87                     [ENOMEM].  In addition, the automatic stack growth  fails
88                     with the effects outlined above.
89
90       When  using the getrlimit() function, if a resource limit can be repre‐
91       sented correctly in an object of type rlim_t, then  its  representation
92       is  returned; otherwise, if the value of the resource limit is equal to
93       that of the corresponding saved hard limit, the value returned shall be
94       RLIM_SAVED_MAX; otherwise, the value returned shall be RLIM_SAVED_CUR.
95
96       When  using  the  setrlimit()  function,  if the requested new limit is
97       RLIM_INFINITY, the new limit shall be ``no limit''; otherwise,  if  the
98       requested  new limit is RLIM_SAVED_MAX, the new limit shall be the cor‐
99       responding saved hard limit; otherwise, if the requested new  limit  is
100       RLIM_SAVED_CUR,  the  new  limit  shall be the corresponding saved soft
101       limit; otherwise, the new limit shall be the requested value. In  addi‐
102       tion,  if the corresponding saved limit can be represented correctly in
103       an object of type rlim_t then it shall  be  overwritten  with  the  new
104       limit.
105
106       The  result  of  setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
107       unspecified unless a previous call to getrlimit() returned  that  value
108       as the soft or hard limit for the corresponding resource limit.
109
110       The determination of whether a limit can be correctly represented in an
111       object of type rlim_t  is  implementation-defined.  For  example,  some
112       implementations  permit a limit whose value is greater than RLIM_INFIN‐
113       ITY and others do not.
114
115       The exec family of functions shall cause resource limits to be saved.
116

RETURN VALUE

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

ERRORS

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

EXAMPLES

140       None.
141

APPLICATION USAGE

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

RATIONALE

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

FUTURE DIRECTIONS

158       None.
159

SEE ALSO

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