logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

getrlimit.3p (8285B)


  1. '\" et
  2. .TH GETRLIMIT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. getrlimit,
  12. setrlimit
  13. \(em control maximum resource consumption
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. #include <sys/resource.h>
  18. .P
  19. int getrlimit(int \fIresource\fP, struct rlimit *\fIrlp\fP);
  20. int setrlimit(int \fIresource\fP, const struct rlimit *\fIrlp\fP);
  21. .fi
  22. .SH DESCRIPTION
  23. The
  24. \fIgetrlimit\fR()
  25. function shall get, and the
  26. \fIsetrlimit\fR()
  27. function shall set, limits on the consumption of a variety of
  28. resources.
  29. .P
  30. Each call to either
  31. \fIgetrlimit\fR()
  32. or
  33. \fIsetrlimit\fR()
  34. identifies a specific resource to be operated upon as well as a
  35. resource limit. A resource limit is represented by an
  36. .BR rlimit
  37. structure. The
  38. .IR rlim_cur
  39. member specifies the current or soft limit and the
  40. .IR rlim_max
  41. member specifies the maximum or hard limit. Soft limits may be changed
  42. by a process to any value that is less than or equal to the hard
  43. limit. A process may (irreversibly) lower its hard limit to any value
  44. that is greater than or equal to the soft limit. Only a process with
  45. appropriate privileges can raise a hard limit. Both hard and soft
  46. limits can be changed in a single call to
  47. \fIsetrlimit\fR()
  48. subject to the constraints described above.
  49. .P
  50. The value RLIM_INFINITY, defined in
  51. .IR <sys/resource.h> ,
  52. shall be considered to be larger than any other limit value. If a
  53. call to
  54. \fIgetrlimit\fR()
  55. returns RLIM_INFINITY for a resource, it means the implementation shall
  56. not enforce limits on that resource. Specifying RLIM_INFINITY as any
  57. resource limit value on a successful call to
  58. \fIsetrlimit\fR()
  59. shall inhibit enforcement of that resource limit.
  60. .P
  61. The following resources are defined:
  62. .IP RLIMIT_CORE 14
  63. This is the maximum size of a
  64. .BR core
  65. file, in bytes, that may be created by a process. A limit of 0 shall
  66. prevent the creation of a
  67. .BR core
  68. file. If this limit is exceeded, the writing of a
  69. .BR core
  70. file shall terminate at this size.
  71. .IP RLIMIT_CPU 14
  72. This is the maximum amount of CPU time, in seconds, used by a process.
  73. If this limit is exceeded, SIGXCPU shall be generated for the process. If
  74. the process is catching or ignoring SIGXCPU, or all threads belonging
  75. to that process are blocking SIGXCPU, the behavior is unspecified.
  76. .IP RLIMIT_DATA 14
  77. This is the maximum size of a data segment of the process, in bytes.
  78. If this limit is exceeded, the
  79. \fImalloc\fR()
  80. function shall fail with
  81. .IR errno
  82. set to
  83. .BR [ENOMEM] .
  84. .IP RLIMIT_FSIZE 14
  85. This is the maximum size of a file, in bytes, that may be created by a
  86. process. If a write or truncate operation would cause this limit to be
  87. exceeded, SIGXFSZ shall be generated for the thread. If the thread is
  88. blocking, or
  89. the process is catching or ignoring SIGXFSZ, continued attempts to
  90. increase the size of a file from end-of-file to beyond the limit
  91. shall fail with
  92. .IR errno
  93. set to
  94. .BR [EFBIG] .
  95. .IP RLIMIT_NOFILE 14
  96. This is a number one greater than the maximum value that the system may
  97. assign to a newly-created descriptor. If this limit is exceeded,
  98. functions that allocate a file descriptor shall fail with
  99. .IR errno
  100. set to
  101. .BR [EMFILE] .
  102. This limit constrains the number of file descriptors that a process may
  103. allocate.
  104. .IP RLIMIT_STACK 14
  105. This is the maximum size of the initial thread's stack, in bytes. The
  106. implementation does not automatically grow the stack beyond this
  107. limit. If this limit is exceeded, SIGSEGV shall be generated for the
  108. thread. If the thread is blocking SIGSEGV, or the process is ignoring
  109. or catching SIGSEGV and has not made arrangements to use an alternate
  110. stack, the disposition of SIGSEGV shall be set to SIG_DFL before it is
  111. generated.
  112. .IP RLIMIT_AS 14
  113. This is the maximum size of total available memory of the process, in
  114. bytes. If this limit is exceeded, the
  115. \fImalloc\fR()
  116. and
  117. \fImmap\fR()
  118. functions shall fail with
  119. .IR errno
  120. set to
  121. .BR [ENOMEM] .
  122. In addition, the automatic stack growth fails with the effects outlined
  123. above.
  124. .P
  125. When using the
  126. \fIgetrlimit\fR()
  127. function, if a resource limit can be represented correctly in an object
  128. of type
  129. .BR rlim_t ,
  130. then its representation is returned; otherwise, if the value of the
  131. resource limit is equal to that of the corresponding saved hard limit,
  132. the value returned shall be RLIM_SAVED_MAX; otherwise, the value
  133. returned shall be RLIM_SAVED_CUR.
  134. .P
  135. When using the
  136. \fIsetrlimit\fR()
  137. function, if the requested new limit is RLIM_INFINITY, the new limit
  138. shall be ``no limit''; otherwise, if the
  139. requested new limit is RLIM_SAVED_MAX, the new limit shall be the
  140. corresponding saved hard limit; otherwise, if the requested new limit
  141. is RLIM_SAVED_CUR, the new limit shall be the corresponding saved soft
  142. limit; otherwise, the new limit shall be the requested value. In
  143. addition, if the corresponding saved limit can be represented correctly
  144. in an object of type
  145. .BR rlim_t
  146. then it shall be overwritten with the new limit.
  147. .P
  148. The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
  149. unspecified unless a previous call to
  150. \fIgetrlimit\fR()
  151. returned that value as the soft or hard limit for the corresponding
  152. resource limit.
  153. .P
  154. The determination of whether a limit can be correctly represented in an
  155. object of type
  156. .BR rlim_t
  157. is implementation-defined. For example, some implementations permit a
  158. limit whose value is greater than RLIM_INFINITY and others do not.
  159. .P
  160. The
  161. .IR exec
  162. family of functions shall cause resource limits to be saved.
  163. .SH "RETURN VALUE"
  164. Upon successful completion,
  165. \fIgetrlimit\fR()
  166. and
  167. \fIsetrlimit\fR()
  168. shall return 0. Otherwise, these functions shall return \-1 and set
  169. .IR errno
  170. to indicate the error.
  171. .SH ERRORS
  172. The
  173. \fIgetrlimit\fR()
  174. and
  175. \fIsetrlimit\fR()
  176. functions shall fail if:
  177. .TP
  178. .BR EINVAL
  179. An invalid
  180. .IR resource
  181. was specified; or in a
  182. \fIsetrlimit\fR()
  183. call, the new
  184. .IR rlim_cur
  185. exceeds the new
  186. .IR rlim_max .
  187. .TP
  188. .BR EPERM
  189. The limit specified to
  190. \fIsetrlimit\fR()
  191. would have raised the maximum limit value, and the calling process does
  192. not have appropriate privileges.
  193. .P
  194. The
  195. \fIsetrlimit\fR()
  196. function may fail if:
  197. .TP
  198. .BR EINVAL
  199. The limit specified cannot be lowered because current usage is already
  200. higher than the limit.
  201. .LP
  202. .IR "The following sections are informative."
  203. .SH EXAMPLES
  204. None.
  205. .SH "APPLICATION USAGE"
  206. If a process attempts to set the hard limit or soft limit for
  207. RLIMIT_NOFILE to less than the value of
  208. {_POSIX_OPEN_MAX}
  209. from
  210. .IR <limits.h> ,
  211. unexpected behavior may occur.
  212. .P
  213. If a process attempts to set the hard limit or soft limit for
  214. RLIMIT_NOFILE to less than the highest currently open file descriptor
  215. +1, unexpected behavior may occur.
  216. .SH RATIONALE
  217. It should be noted that RLIMIT_STACK applies ``at least'' to the stack
  218. of the initial thread in the process, and not to the sum of all the
  219. stacks in the process, as that would be very limiting unless the value
  220. is so big as to provide no value at all with a single thread.
  221. .SH "FUTURE DIRECTIONS"
  222. None.
  223. .SH "SEE ALSO"
  224. .IR "\fIexec\fR\^",
  225. .IR "\fIfork\fR\^(\|)",
  226. .IR "\fImalloc\fR\^(\|)",
  227. .IR "\fIopen\fR\^(\|)",
  228. .IR "\fIsigaltstack\fR\^(\|)",
  229. .IR "\fIsysconf\fR\^(\|)",
  230. .IR "\fIulimit\fR\^(\|)"
  231. .P
  232. The Base Definitions volume of POSIX.1\(hy2017,
  233. .IR "\fB<stropts.h>\fP",
  234. .IR "\fB<sys_resource.h>\fP"
  235. .\"
  236. .SH COPYRIGHT
  237. Portions of this text are reprinted and reproduced in electronic form
  238. from IEEE Std 1003.1-2017, Standard for Information Technology
  239. -- Portable Operating System Interface (POSIX), The Open Group Base
  240. Specifications Issue 7, 2018 Edition,
  241. Copyright (C) 2018 by the Institute of
  242. Electrical and Electronics Engineers, Inc and The Open Group.
  243. In the event of any discrepancy between this version and the original IEEE and
  244. The Open Group Standard, the original IEEE and The Open Group Standard
  245. is the referee document. The original Standard can be obtained online at
  246. http://www.opengroup.org/unix/online.html .
  247. .PP
  248. Any typographical or formatting errors that appear
  249. in this page are most likely
  250. to have been introduced during the conversion of the source files to
  251. man page format. To report such errors, see
  252. https://www.kernel.org/doc/man-pages/reporting_bugs.html .