resource.h 9.2 KB

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