1/* Bit values & structures for resource limits. Linux version.
2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_RESOURCE_H
20# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
21#endif
22
23#include <bits/types.h>
24
25/* Transmute defines to enumerations. The macro re-definitions are
26 necessary because some programs want to test for operating system
27 features with #ifdef RUSAGE_SELF. In ISO C the reflexive
28 definition is a no-op. */
29
30/* Kinds of resource limit. */
31enum __rlimit_resource
32{
33 /* Per-process CPU limit, in seconds. */
34 RLIMIT_CPU = 0,
35#define RLIMIT_CPU RLIMIT_CPU
36
37 /* Largest file that can be created, in bytes. */
38 RLIMIT_FSIZE = 1,
39#define RLIMIT_FSIZE RLIMIT_FSIZE
40
41 /* Maximum size of data segment, in bytes. */
42 RLIMIT_DATA = 2,
43#define RLIMIT_DATA RLIMIT_DATA
44
45 /* Maximum size of stack segment, in bytes. */
46 RLIMIT_STACK = 3,
47#define RLIMIT_STACK RLIMIT_STACK
48
49 /* Largest core file that can be created, in bytes. */
50 RLIMIT_CORE = 4,
51#define RLIMIT_CORE RLIMIT_CORE
52
53 /* Largest resident set size, in bytes.
54 This affects swapping; processes that are exceeding their
55 resident set size will be more likely to have physical memory
56 taken from them. */
57 __RLIMIT_RSS = 5,
58#define RLIMIT_RSS __RLIMIT_RSS
59
60 /* Number of open files. */
61 RLIMIT_NOFILE = 7,
62 __RLIMIT_OFILE = RLIMIT_NOFILE, /* BSD name for same. */
63#define RLIMIT_NOFILE RLIMIT_NOFILE
64#define RLIMIT_OFILE __RLIMIT_OFILE
65
66 /* Address space limit. */
67 RLIMIT_AS = 9,
68#define RLIMIT_AS RLIMIT_AS
69
70 /* Number of processes. */
71 __RLIMIT_NPROC = 6,
72#define RLIMIT_NPROC __RLIMIT_NPROC
73
74 /* Locked-in-memory address space. */
75 __RLIMIT_MEMLOCK = 8,
76#define RLIMIT_MEMLOCK __RLIMIT_MEMLOCK
77
78 /* Maximum number of file locks. */
79 __RLIMIT_LOCKS = 10,
80#define RLIMIT_LOCKS __RLIMIT_LOCKS
81
82 /* Maximum number of pending signals. */
83 __RLIMIT_SIGPENDING = 11,
84#define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
85
86 /* Maximum bytes in POSIX message queues. */
87 __RLIMIT_MSGQUEUE = 12,
88#define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
89
90 /* Maximum nice priority allowed to raise to.
91 Nice levels 19 .. -20 correspond to 0 .. 39
92 values of this resource limit. */
93 __RLIMIT_NICE = 13,
94#define RLIMIT_NICE __RLIMIT_NICE
95
96 /* Maximum realtime priority allowed for non-priviledged
97 processes. */
98 __RLIMIT_RTPRIO = 14,
99#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
100
101 /* Maximum CPU time in ┬Ás that a process scheduled under a real-time
102 scheduling policy may consume without making a blocking system
103 call before being forcibly descheduled. */
104 __RLIMIT_RTTIME = 15,
105#define RLIMIT_RTTIME __RLIMIT_RTTIME
106
107 __RLIMIT_NLIMITS = 16,
108 __RLIM_NLIMITS = __RLIMIT_NLIMITS
109#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
110#define RLIM_NLIMITS __RLIM_NLIMITS
111};
112
113/* Value to indicate that there is no limit. */
114#ifndef __USE_FILE_OFFSET64
115# define RLIM_INFINITY ((__rlim_t) -1)
116#else
117# define RLIM_INFINITY 0xffffffffffffffffuLL
118#endif
119
120#ifdef __USE_LARGEFILE64
121# define RLIM64_INFINITY 0xffffffffffffffffuLL
122#endif
123
124/* We can represent all limits. */
125#define RLIM_SAVED_MAX RLIM_INFINITY
126#define RLIM_SAVED_CUR RLIM_INFINITY
127
128
129/* Type for resource quantity measurement. */
130#ifndef __USE_FILE_OFFSET64
131typedef __rlim_t rlim_t;
132#else
133typedef __rlim64_t rlim_t;
134#endif
135#ifdef __USE_LARGEFILE64
136typedef __rlim64_t rlim64_t;
137#endif
138
139struct rlimit
140 {
141 /* The current (soft) limit. */
142 rlim_t rlim_cur;
143 /* The hard limit. */
144 rlim_t rlim_max;
145 };
146
147#ifdef __USE_LARGEFILE64
148struct rlimit64
149 {
150 /* The current (soft) limit. */
151 rlim64_t rlim_cur;
152 /* The hard limit. */
153 rlim64_t rlim_max;
154 };
155#endif
156
157/* Whose usage statistics do you want? */
158enum __rusage_who
159{
160 /* The calling process. */
161 RUSAGE_SELF = 0,
162#define RUSAGE_SELF RUSAGE_SELF
163
164 /* All of its terminated child processes. */
165 RUSAGE_CHILDREN = -1
166#define RUSAGE_CHILDREN RUSAGE_CHILDREN
167
168#ifdef __USE_GNU
169 ,
170 /* The calling thread. */
171 RUSAGE_THREAD = 1
172# define RUSAGE_THREAD RUSAGE_THREAD
173 /* Name for the same functionality on Solaris. */
174# define RUSAGE_LWP RUSAGE_THREAD
175#endif
176};
177
178#include <bits/types/struct_timeval.h>
179
180/* Structure which says how much of each resource has been used. */
181
182/* The purpose of all the unions is to have the kernel-compatible layout
183 while keeping the API type as 'long int', and among machines where
184 __syscall_slong_t is not 'long int', this only does the right thing
185 for little-endian ones, like x32. */
186struct rusage
187 {
188 /* Total amount of user time used. */
189 struct timeval ru_utime;
190 /* Total amount of system time used. */
191 struct timeval ru_stime;
192 /* Maximum resident set size (in kilobytes). */
193 __extension__ union
194 {
195 long int ru_maxrss;
196 __syscall_slong_t __ru_maxrss_word;
197 };
198 /* Amount of sharing of text segment memory
199 with other processes (kilobyte-seconds). */
200 /* Maximum resident set size (in kilobytes). */
201 __extension__ union
202 {
203 long int ru_ixrss;
204 __syscall_slong_t __ru_ixrss_word;
205 };
206 /* Amount of data segment memory used (kilobyte-seconds). */
207 __extension__ union
208 {
209 long int ru_idrss;
210 __syscall_slong_t __ru_idrss_word;
211 };
212 /* Amount of stack memory used (kilobyte-seconds). */
213 __extension__ union
214 {
215 long int ru_isrss;
216 __syscall_slong_t __ru_isrss_word;
217 };
218 /* Number of soft page faults (i.e. those serviced by reclaiming
219 a page from the list of pages awaiting reallocation. */
220 __extension__ union
221 {
222 long int ru_minflt;
223 __syscall_slong_t __ru_minflt_word;
224 };
225 /* Number of hard page faults (i.e. those that required I/O). */
226 __extension__ union
227 {
228 long int ru_majflt;
229 __syscall_slong_t __ru_majflt_word;
230 };
231 /* Number of times a process was swapped out of physical memory. */
232 __extension__ union
233 {
234 long int ru_nswap;
235 __syscall_slong_t __ru_nswap_word;
236 };
237 /* Number of input operations via the file system. Note: This
238 and `ru_oublock' do not include operations with the cache. */
239 __extension__ union
240 {
241 long int ru_inblock;
242 __syscall_slong_t __ru_inblock_word;
243 };
244 /* Number of output operations via the file system. */
245 __extension__ union
246 {
247 long int ru_oublock;
248 __syscall_slong_t __ru_oublock_word;
249 };
250 /* Number of IPC messages sent. */
251 __extension__ union
252 {
253 long int ru_msgsnd;
254 __syscall_slong_t __ru_msgsnd_word;
255 };
256 /* Number of IPC messages received. */
257 __extension__ union
258 {
259 long int ru_msgrcv;
260 __syscall_slong_t __ru_msgrcv_word;
261 };
262 /* Number of signals delivered. */
263 __extension__ union
264 {
265 long int ru_nsignals;
266 __syscall_slong_t __ru_nsignals_word;
267 };
268 /* Number of voluntary context switches, i.e. because the process
269 gave up the process before it had to (usually to wait for some
270 resource to be available). */
271 __extension__ union
272 {
273 long int ru_nvcsw;
274 __syscall_slong_t __ru_nvcsw_word;
275 };
276 /* Number of involuntary context switches, i.e. a higher priority process
277 became runnable or the current process used up its time slice. */
278 __extension__ union
279 {
280 long int ru_nivcsw;
281 __syscall_slong_t __ru_nivcsw_word;
282 };
283 };
284
285/* Priority limits. */
286#define PRIO_MIN -20 /* Minimum priority a process can have. */
287#define PRIO_MAX 20 /* Maximum priority a process can have. */
288
289/* The type of the WHICH argument to `getpriority' and `setpriority',
290 indicating what flavor of entity the WHO argument specifies. */
291enum __priority_which
292{
293 PRIO_PROCESS = 0, /* WHO is a process ID. */
294#define PRIO_PROCESS PRIO_PROCESS
295 PRIO_PGRP = 1, /* WHO is a process group ID. */
296#define PRIO_PGRP PRIO_PGRP
297 PRIO_USER = 2 /* WHO is a user ID. */
298#define PRIO_USER PRIO_USER
299};
300
301
302__BEGIN_DECLS
303
304#ifdef __USE_GNU
305/* Modify and return resource limits of a process atomically. */
306# ifndef __USE_FILE_OFFSET64
307extern int prlimit (__pid_t __pid, enum __rlimit_resource __resource,
308 const struct rlimit *__new_limit,
309 struct rlimit *__old_limit) __THROW;
310# else
311# ifdef __REDIRECT_NTH
312extern int __REDIRECT_NTH (prlimit, (__pid_t __pid,
313 enum __rlimit_resource __resource,
314 const struct rlimit *__new_limit,
315 struct rlimit *__old_limit), prlimit64);
316# else
317# define prlimit prlimit64
318# endif
319# endif
320# ifdef __USE_LARGEFILE64
321extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource,
322 const struct rlimit64 *__new_limit,
323 struct rlimit64 *__old_limit) __THROW;
324# endif
325#endif
326
327__END_DECLS
328