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

NAME

6       getrlimit, setrlimit - control maximum resource consumption
7

SYNOPSIS

9       #include <sys/resource.h>
10
11       int getrlimit(int resource, struct rlimit *rlp);
12       int setrlimit(int resource, const struct rlimit *rlp);
13
14

DESCRIPTION

16       The  getrlimit() function shall get, and the setrlimit() function shall
17       set, limits on the consumption of a variety of resources.
18
19       Each call to either getrlimit() or setrlimit()  identifies  a  specific
20       resource  to  be  operated upon as well as a resource limit. A resource
21       limit is represented by an rlimit structure. The rlim_cur member speci‐
22       fies  the  current  or soft limit and the rlim_max member specifies the
23       maximum or hard limit. Soft limits may be changed by a process  to  any
24       value  that  is  less  than  or  equal to the hard limit. A process may
25       (irreversibly) lower its hard limit to any value that is  greater  than
26       or  equal to the soft limit. Only a process with appropriate privileges
27       can raise a hard limit. Both hard and soft limits can be changed  in  a
28       single call to setrlimit() subject to the constraints described above.
29
30       The  value RLIM_INFINITY, defined in <sys/resource.h>, shall be consid‐
31       ered to be larger than any other limit value. If a call to  getrlimit()
32       returns RLIM_INFINITY for a resource, it means the implementation shall
33       not enforce limits on that resource. Specifying  RLIM_INFINITY  as  any
34       resource  limit value on a successful call to setrlimit() shall inhibit
35       enforcement of that resource limit.
36
37       The following resources are defined:
38
39       RLIMIT_CORE
40              This is the maximum size of a core file, in bytes, that  may  be
41              created by a process. A limit of 0 shall prevent the creation of
42              a core file. If this limit is exceeded, the writing  of  a  core
43              file shall terminate at this size.
44
45       RLIMIT_CPU
46              This  is  the  maximum amount of CPU time, in seconds, used by a
47              process.  If this limit is exceeded, SIGXCPU shall be  generated
48              for the process. If the process is catching or ignoring SIGXCPU,
49              or all threads belonging to that process are  blocking  SIGXCPU,
50              the behavior is unspecified.
51
52       RLIMIT_DATA
53              This  is  the maximum size of a process' data segment, in bytes.
54              If this limit is exceeded, the malloc() function shall fail with
55              errno set to [ENOMEM].
56
57       RLIMIT_FSIZE
58              This  is  the maximum size of a file, in bytes, that may be cre‐
59              ated by a process. If a write or truncate operation would  cause
60              this  limit  to  be exceeded, SIGXFSZ shall be generated for the
61              thread.  If the thread is blocking, or the process  is  catching
62              or  ignoring SIGXFSZ, continued attempts to increase the size of
63              a file from end-of-file to beyond  the  limit  shall  fail  with
64              errno set to [EFBIG].
65
66       RLIMIT_NOFILE
67              This  is  a  number  one greater than the maximum value that the
68              system may assign to a newly-created descriptor. If  this  limit
69              is  exceeded,  functions  that  allocate a file descriptor shall
70              fail with errno set to [EMFILE]. This limit constrains the  num‐
71              ber of file descriptors that a process may allocate.
72
73       RLIMIT_STACK
74              This  is  the  maximum  size  of a process' stack, in bytes. The
75              implementation does not automatically grow the stack beyond this
76              limit. If this limit is exceeded, SIGSEGV shall be generated for
77              the thread. If the thread is blocking SIGSEGV, or the process is
78              ignoring  or  catching  SIGSEGV and has not made arrangements to
79              use an alternate stack, the disposition of SIGSEGV shall be  set
80              to SIG_DFL before it is generated.
81
82       RLIMIT_AS
83              This  is  the maximum size of a process' total available memory,
84              in bytes. If this limit is exceeded,  the  malloc()  and  mmap()
85              functions  shall  fail  with errno set to [ENOMEM]. In addition,
86              the automatic stack  growth  fails  with  the  effects  outlined
87              above.
88
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
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
139       The following sections are informative.
140

EXAMPLES

142       None.
143

APPLICATION USAGE

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

RATIONALE

154       None.
155

FUTURE DIRECTIONS

157       None.
158

SEE ALSO

160       exec() , fork() , malloc() ,  open()  ,  sigaltstack()  ,  sysconf()  ,
161       ulimit()   ,  the  Base  Definitions  volume  of  IEEE Std 1003.1-2001,
162       <stropts.h>, <sys/resource.h>
163
165       Portions of this text are reprinted and reproduced in  electronic  form
166       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
167       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
168       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
169       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
170       event of any discrepancy between this version and the original IEEE and
171       The Open Group Standard, the original IEEE and The Open Group  Standard
172       is  the  referee document. The original Standard can be obtained online
173       at http://www.opengroup.org/unix/online.html .
174
175
176
177IEEE/The Open Group                  2003                         GETRLIMIT(P)
Impressum