resource.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Bit values & structures for resource limits. Linux version.
  17. Copyright (C) 1994-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #ifndef _SYS_RESOURCE_H
  31. # error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
  32. #endif
  33. #include <bits/types.h>
  34. /* Transmute defines to enumerations. The macro re-definitions are
  35. necessary because some programs want to test for operating system
  36. features with #ifdef RUSAGE_SELF. In ISO C the reflexive
  37. definition is a no-op. */
  38. /* Kinds of resource limit. */
  39. enum __rlimit_resource
  40. {
  41. /* Per-process CPU limit, in seconds. */
  42. RLIMIT_CPU = 0,
  43. #define RLIMIT_CPU RLIMIT_CPU
  44. /* Largest file that can be created, in bytes. */
  45. RLIMIT_FSIZE = 1,
  46. #define RLIMIT_FSIZE RLIMIT_FSIZE
  47. /* Maximum size of data segment, in bytes. */
  48. RLIMIT_DATA = 2,
  49. #define RLIMIT_DATA RLIMIT_DATA
  50. /* Maximum size of stack segment, in bytes. */
  51. RLIMIT_STACK = 3,
  52. #define RLIMIT_STACK RLIMIT_STACK
  53. /* Largest core file that can be created, in bytes. */
  54. RLIMIT_CORE = 4,
  55. #define RLIMIT_CORE RLIMIT_CORE
  56. /* Largest resident set size, in bytes.
  57. This affects swapping; processes that are exceeding their
  58. resident set size will be more likely to have physical memory
  59. taken from them. */
  60. __RLIMIT_RSS = 5,
  61. #define RLIMIT_RSS __RLIMIT_RSS
  62. /* Number of open files. */
  63. RLIMIT_NOFILE = 7,
  64. __RLIMIT_OFILE = RLIMIT_NOFILE, /* BSD name for same. */
  65. #define RLIMIT_NOFILE RLIMIT_NOFILE
  66. #define RLIMIT_OFILE __RLIMIT_OFILE
  67. /* Address space limit. */
  68. RLIMIT_AS = 9,
  69. #define RLIMIT_AS RLIMIT_AS
  70. /* Number of processes. */
  71. __RLIMIT_NPROC = 6,
  72. #define RLIMIT_NPROC __RLIMIT_NPROC
  73. /* Locked-in-memory address space. */
  74. __RLIMIT_MEMLOCK = 8,
  75. #define RLIMIT_MEMLOCK __RLIMIT_MEMLOCK
  76. /* Maximum number of file locks. */
  77. __RLIMIT_LOCKS = 10,
  78. #define RLIMIT_LOCKS __RLIMIT_LOCKS
  79. /* Maximum number of pending signals. */
  80. __RLIMIT_SIGPENDING = 11,
  81. #define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
  82. /* Maximum bytes in POSIX message queues. */
  83. __RLIMIT_MSGQUEUE = 12,
  84. #define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
  85. /* Maximum nice priority allowed to raise to.
  86. Nice levels 19 .. -20 correspond to 0 .. 39
  87. values of this resource limit. */
  88. __RLIMIT_NICE = 13,
  89. #define RLIMIT_NICE __RLIMIT_NICE
  90. /* Maximum realtime priority allowed for non-priviledged
  91. processes. */
  92. __RLIMIT_RTPRIO = 14,
  93. #define RLIMIT_RTPRIO __RLIMIT_RTPRIO
  94. /* Maximum CPU time in microseconds that a process scheduled under a real-time
  95. scheduling policy may consume without making a blocking system
  96. call before being forcibly descheduled. */
  97. __RLIMIT_RTTIME = 15,
  98. #define RLIMIT_RTTIME __RLIMIT_RTTIME
  99. __RLIMIT_NLIMITS = 16,
  100. __RLIM_NLIMITS = __RLIMIT_NLIMITS
  101. #define RLIMIT_NLIMITS __RLIMIT_NLIMITS
  102. #define RLIM_NLIMITS __RLIM_NLIMITS
  103. };
  104. /* Value to indicate that there is no limit. */
  105. #ifndef __USE_FILE_OFFSET64
  106. # define RLIM_INFINITY ((__rlim_t) -1)
  107. #else
  108. # define RLIM_INFINITY 0xffffffffffffffffuLL
  109. #endif
  110. #ifdef __USE_LARGEFILE64
  111. # define RLIM64_INFINITY 0xffffffffffffffffuLL
  112. #endif
  113. /* We can represent all limits. */
  114. #define RLIM_SAVED_MAX RLIM_INFINITY
  115. #define RLIM_SAVED_CUR RLIM_INFINITY
  116. /* Type for resource quantity measurement. */
  117. #ifndef __USE_FILE_OFFSET64
  118. typedef __rlim_t rlim_t;
  119. #else
  120. typedef __rlim64_t rlim_t;
  121. #endif
  122. #ifdef __USE_LARGEFILE64
  123. typedef __rlim64_t rlim64_t;
  124. #endif
  125. struct rlimit
  126. {
  127. /* The current (soft) limit. */
  128. rlim_t rlim_cur;
  129. /* The hard limit. */
  130. rlim_t rlim_max;
  131. };
  132. #ifdef __USE_LARGEFILE64
  133. struct rlimit64
  134. {
  135. /* The current (soft) limit. */
  136. rlim64_t rlim_cur;
  137. /* The hard limit. */
  138. rlim64_t rlim_max;
  139. };
  140. #endif
  141. /* Whose usage statistics do you want? */
  142. enum __rusage_who
  143. {
  144. /* The calling process. */
  145. RUSAGE_SELF = 0,
  146. #define RUSAGE_SELF RUSAGE_SELF
  147. /* All of its terminated child processes. */
  148. RUSAGE_CHILDREN = -1
  149. #define RUSAGE_CHILDREN RUSAGE_CHILDREN
  150. #ifdef __USE_GNU
  151. ,
  152. /* The calling thread. */
  153. RUSAGE_THREAD = 1
  154. # define RUSAGE_THREAD RUSAGE_THREAD
  155. /* Name for the same functionality on Solaris. */
  156. # define RUSAGE_LWP RUSAGE_THREAD
  157. #endif
  158. };
  159. #include <bits/types/struct_timeval.h>
  160. #include <bits/types/struct_rusage.h>
  161. /* Priority limits. */
  162. #define PRIO_MIN -20 /* Minimum priority a process can have. */
  163. #define PRIO_MAX 20 /* Maximum priority a process can have. */
  164. /* The type of the WHICH argument to `getpriority' and `setpriority',
  165. indicating what flavor of entity the WHO argument specifies. */
  166. enum __priority_which
  167. {
  168. PRIO_PROCESS = 0, /* WHO is a process ID. */
  169. #define PRIO_PROCESS PRIO_PROCESS
  170. PRIO_PGRP = 1, /* WHO is a process group ID. */
  171. #define PRIO_PGRP PRIO_PGRP
  172. PRIO_USER = 2 /* WHO is a user ID. */
  173. #define PRIO_USER PRIO_USER
  174. };
  175. __BEGIN_DECLS
  176. #ifdef __USE_GNU
  177. /* Modify and return resource limits of a process atomically. */
  178. # ifndef __USE_FILE_OFFSET64
  179. extern int prlimit (__pid_t __pid, enum __rlimit_resource __resource,
  180. const struct rlimit *__new_limit,
  181. struct rlimit *__old_limit) __THROW;
  182. # else
  183. # ifdef __REDIRECT_NTH
  184. extern int __REDIRECT_NTH (prlimit, (__pid_t __pid,
  185. enum __rlimit_resource __resource,
  186. const struct rlimit *__new_limit,
  187. struct rlimit *__old_limit), prlimit64);
  188. # else
  189. # define prlimit prlimit64
  190. # endif
  191. # endif
  192. # ifdef __USE_LARGEFILE64
  193. extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource,
  194. const struct rlimit64 *__new_limit,
  195. struct rlimit64 *__old_limit) __THROW;
  196. # endif
  197. #endif
  198. __END_DECLS