rbs 2.8.4 → 3.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (434) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +12 -4
  3. data/.github/workflows/comments.yml +11 -11
  4. data/.github/workflows/dependabot.yml +30 -0
  5. data/.github/workflows/ruby.yml +40 -49
  6. data/.github/workflows/typecheck.yml +36 -0
  7. data/.github/workflows/windows.yml +28 -0
  8. data/.gitignore +1 -0
  9. data/.rubocop.yml +42 -2
  10. data/CHANGELOG.md +845 -1
  11. data/README.md +64 -4
  12. data/Rakefile +198 -18
  13. data/Steepfile +11 -11
  14. data/config.yml +311 -0
  15. data/core/array.rbs +2189 -1914
  16. data/core/basic_object.rbs +59 -84
  17. data/core/binding.rbs +7 -69
  18. data/core/builtin.rbs +210 -11
  19. data/core/class.rbs +37 -0
  20. data/core/comparable.rbs +23 -25
  21. data/core/complex.rbs +449 -227
  22. data/core/constants.rbs +29 -21
  23. data/core/data.rbs +415 -0
  24. data/core/dir.rbs +698 -415
  25. data/core/encoding.rbs +468 -843
  26. data/core/enumerable.rbs +495 -455
  27. data/core/enumerator/product.rbs +92 -0
  28. data/core/enumerator.rbs +106 -9
  29. data/core/env.rbs +1 -1
  30. data/core/errno.rbs +506 -605
  31. data/core/errors.rbs +15 -17
  32. data/core/exception.rbs +361 -145
  33. data/core/false_class.rbs +39 -26
  34. data/core/fiber.rbs +121 -14
  35. data/core/file.rbs +1262 -320
  36. data/core/file_test.rbs +62 -45
  37. data/core/float.rbs +187 -208
  38. data/core/gc.rbs +446 -196
  39. data/core/global_variables.rbs +29 -29
  40. data/core/hash.rbs +242 -349
  41. data/core/integer.rbs +246 -308
  42. data/core/io/buffer.rbs +373 -122
  43. data/core/io/wait.rbs +29 -17
  44. data/core/io.rbs +1881 -1518
  45. data/core/kernel.rbs +2116 -1538
  46. data/core/marshal.rbs +24 -14
  47. data/core/match_data.rbs +413 -166
  48. data/core/math.rbs +531 -291
  49. data/core/method.rbs +101 -32
  50. data/core/module.rbs +228 -64
  51. data/core/nil_class.rbs +106 -47
  52. data/core/numeric.rbs +206 -292
  53. data/core/object.rbs +73 -1168
  54. data/core/object_space/weak_key_map.rbs +166 -0
  55. data/core/object_space.rbs +5 -3
  56. data/core/proc.rbs +280 -39
  57. data/core/process.rbs +1318 -658
  58. data/core/ractor.rbs +200 -134
  59. data/core/random.rbs +21 -4
  60. data/core/range.rbs +309 -153
  61. data/core/rational.rbs +4 -12
  62. data/core/rb_config.rbs +64 -43
  63. data/core/rbs/unnamed/argf.rbs +411 -147
  64. data/core/rbs/unnamed/env_class.rbs +137 -253
  65. data/core/rbs/unnamed/random.rbs +49 -26
  66. data/core/refinement.rbs +16 -1
  67. data/core/regexp.rbs +1568 -862
  68. data/core/ruby_vm.rbs +719 -7
  69. data/core/rubygems/config_file.rbs +3 -0
  70. data/core/rubygems/errors.rbs +69 -6
  71. data/core/rubygems/rubygems.rbs +71 -17
  72. data/core/rubygems/version.rbs +11 -7
  73. data/{stdlib/set/0 → core}/set.rbs +80 -91
  74. data/core/signal.rbs +14 -8
  75. data/core/string.rbs +1732 -1607
  76. data/core/struct.rbs +467 -95
  77. data/core/symbol.rbs +215 -245
  78. data/core/thread.rbs +133 -89
  79. data/core/thread_group.rbs +9 -9
  80. data/core/time.rbs +1141 -841
  81. data/core/trace_point.rbs +181 -121
  82. data/core/true_class.rbs +58 -32
  83. data/core/unbound_method.rbs +103 -30
  84. data/core/warning.rbs +50 -5
  85. data/docs/CONTRIBUTING.md +1 -1
  86. data/docs/architecture.md +110 -0
  87. data/docs/collection.md +59 -5
  88. data/docs/data_and_struct.md +86 -0
  89. data/docs/gem.md +57 -0
  90. data/docs/rbs_by_example.md +16 -35
  91. data/docs/repo.md +1 -1
  92. data/docs/sigs.md +7 -7
  93. data/docs/stdlib.md +63 -5
  94. data/docs/syntax.md +255 -61
  95. data/docs/tools.md +1 -0
  96. data/ext/rbs_extension/extconf.rb +10 -0
  97. data/ext/rbs_extension/lexer.c +1741 -1548
  98. data/ext/rbs_extension/lexer.h +11 -1
  99. data/ext/rbs_extension/lexer.re +12 -6
  100. data/ext/rbs_extension/lexstate.c +26 -3
  101. data/ext/rbs_extension/location.c +119 -111
  102. data/ext/rbs_extension/location.h +32 -7
  103. data/ext/rbs_extension/main.c +3 -0
  104. data/ext/rbs_extension/parser.c +883 -481
  105. data/ext/rbs_extension/parserstate.c +65 -25
  106. data/ext/rbs_extension/parserstate.h +13 -3
  107. data/ext/rbs_extension/rbs_extension.h +1 -10
  108. data/ext/rbs_extension/unescape.c +7 -47
  109. data/goodcheck.yml +2 -2
  110. data/{ext/rbs_extension → include/rbs}/constants.h +26 -15
  111. data/include/rbs/ruby_objs.h +72 -0
  112. data/include/rbs.h +7 -0
  113. data/lib/rbs/annotate/annotations.rb +3 -3
  114. data/lib/rbs/annotate/formatter.rb +13 -3
  115. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  116. data/lib/rbs/annotate/rdoc_source.rb +12 -3
  117. data/lib/rbs/ast/declarations.rb +85 -2
  118. data/lib/rbs/ast/directives.rb +39 -0
  119. data/lib/rbs/ast/members.rb +49 -15
  120. data/lib/rbs/ast/type_param.rb +104 -15
  121. data/lib/rbs/ast/visitor.rb +137 -0
  122. data/lib/rbs/buffer.rb +5 -0
  123. data/lib/rbs/cli/colored_io.rb +48 -0
  124. data/lib/rbs/cli/diff.rb +83 -0
  125. data/lib/rbs/cli/validate.rb +356 -0
  126. data/lib/rbs/cli.rb +253 -143
  127. data/lib/rbs/collection/cleaner.rb +8 -1
  128. data/lib/rbs/collection/config/lockfile.rb +92 -0
  129. data/lib/rbs/collection/config/lockfile_generator.rb +154 -65
  130. data/lib/rbs/collection/config.rb +19 -46
  131. data/lib/rbs/collection/installer.rb +12 -13
  132. data/lib/rbs/collection/sources/base.rb +2 -2
  133. data/lib/rbs/collection/sources/git.rb +146 -69
  134. data/lib/rbs/collection/sources/local.rb +81 -0
  135. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  136. data/lib/rbs/collection/sources/stdlib.rb +14 -13
  137. data/lib/rbs/collection/sources.rb +15 -2
  138. data/lib/rbs/collection.rb +2 -1
  139. data/lib/rbs/definition.rb +13 -16
  140. data/lib/rbs/definition_builder/ancestor_builder.rb +100 -24
  141. data/lib/rbs/definition_builder/method_builder.rb +4 -4
  142. data/lib/rbs/definition_builder.rb +489 -584
  143. data/lib/rbs/diff.rb +125 -0
  144. data/lib/rbs/environment/use_map.rb +77 -0
  145. data/lib/rbs/environment.rb +406 -105
  146. data/lib/rbs/environment_loader.rb +48 -44
  147. data/lib/rbs/environment_walker.rb +1 -1
  148. data/lib/rbs/errors.rb +175 -56
  149. data/lib/rbs/file_finder.rb +28 -0
  150. data/lib/rbs/location_aux.rb +8 -7
  151. data/lib/rbs/locator.rb +37 -15
  152. data/lib/rbs/method_type.rb +23 -0
  153. data/lib/rbs/namespace.rb +1 -0
  154. data/lib/rbs/parser/lex_result.rb +15 -0
  155. data/lib/rbs/parser/token.rb +23 -0
  156. data/lib/rbs/parser_aux.rb +22 -13
  157. data/lib/rbs/prototype/helpers.rb +48 -22
  158. data/lib/rbs/prototype/node_usage.rb +99 -0
  159. data/lib/rbs/prototype/rb.rb +125 -31
  160. data/lib/rbs/prototype/rbi.rb +49 -36
  161. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  162. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  163. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  164. data/lib/rbs/prototype/runtime.rb +273 -159
  165. data/lib/rbs/resolver/constant_resolver.rb +24 -8
  166. data/lib/rbs/resolver/type_name_resolver.rb +41 -7
  167. data/lib/rbs/sorter.rb +153 -123
  168. data/lib/rbs/substitution.rb +19 -0
  169. data/lib/rbs/subtractor.rb +201 -0
  170. data/lib/rbs/test/errors.rb +24 -11
  171. data/lib/rbs/test/guaranteed.rb +30 -0
  172. data/lib/rbs/test/hook.rb +45 -40
  173. data/lib/rbs/test/setup.rb +1 -1
  174. data/lib/rbs/test/tester.rb +1 -1
  175. data/lib/rbs/test/type_check.rb +120 -23
  176. data/lib/rbs/test.rb +6 -3
  177. data/lib/rbs/type_alias_dependency.rb +13 -3
  178. data/lib/rbs/type_alias_regularity.rb +21 -14
  179. data/lib/rbs/type_name.rb +18 -13
  180. data/lib/rbs/types.rb +352 -18
  181. data/lib/rbs/unit_test/convertibles.rb +176 -0
  182. data/lib/rbs/unit_test/spy.rb +136 -0
  183. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  184. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  185. data/lib/rbs/unit_test.rb +6 -0
  186. data/lib/rbs/validator.rb +55 -30
  187. data/lib/rbs/variance_calculator.rb +26 -23
  188. data/lib/rbs/vendorer.rb +3 -3
  189. data/lib/rbs/version.rb +1 -1
  190. data/lib/rbs/writer.rb +69 -22
  191. data/lib/rbs.rb +7 -2
  192. data/lib/rdoc/discover.rb +1 -1
  193. data/lib/rdoc_plugin/parser.rb +5 -5
  194. data/rbs.gemspec +12 -2
  195. data/schema/decls.json +1 -1
  196. data/schema/members.json +15 -10
  197. data/sig/ancestor_builder.rbs +4 -0
  198. data/sig/ancestor_graph.rbs +22 -2
  199. data/sig/annotate/formatter.rbs +2 -2
  200. data/sig/annotate/rdoc_annotater.rbs +1 -1
  201. data/sig/cli/colored_io.rbs +15 -0
  202. data/sig/cli/diff.rbs +21 -0
  203. data/sig/cli/validate.rbs +43 -0
  204. data/sig/cli.rbs +4 -0
  205. data/sig/collection/config/lockfile.rbs +74 -0
  206. data/sig/collection/config/lockfile_generator.rbs +66 -0
  207. data/sig/collection/config.rbs +5 -48
  208. data/sig/collection/installer.rbs +1 -1
  209. data/sig/collection/sources.rbs +105 -33
  210. data/sig/constant.rbs +1 -1
  211. data/sig/declarations.rbs +42 -3
  212. data/sig/definition.rbs +26 -10
  213. data/sig/definition_builder.rbs +103 -81
  214. data/sig/diff.rbs +28 -0
  215. data/sig/directives.rbs +61 -0
  216. data/sig/environment.rbs +175 -29
  217. data/sig/environment_loader.rbs +20 -18
  218. data/sig/errors.rbs +123 -2
  219. data/sig/file_finder.rbs +28 -0
  220. data/sig/location.rbs +0 -3
  221. data/sig/locator.rbs +14 -2
  222. data/sig/manifest.yaml +0 -1
  223. data/sig/members.rbs +32 -9
  224. data/sig/method_types.rbs +10 -4
  225. data/sig/namespace.rbs +2 -3
  226. data/sig/parser.rbs +55 -16
  227. data/sig/prototype/helpers.rbs +4 -0
  228. data/sig/prototype/node_usage.rbs +20 -0
  229. data/sig/prototype/rb.rbs +10 -2
  230. data/sig/prototype/rbi.rbs +2 -0
  231. data/sig/prototype/runtime.rbs +182 -0
  232. data/sig/rbs.rbs +1 -1
  233. data/sig/rdoc/rbs.rbs +4 -0
  234. data/sig/repository.rbs +7 -5
  235. data/sig/resolver/constant_resolver.rbs +3 -4
  236. data/sig/resolver/context.rbs +1 -1
  237. data/sig/resolver/type_name_resolver.rbs +5 -1
  238. data/sig/shims/bundler.rbs +38 -0
  239. data/sig/shims/rubygems.rbs +19 -0
  240. data/sig/sorter.rbs +23 -5
  241. data/sig/substitution.rbs +6 -0
  242. data/sig/subtractor.rbs +37 -0
  243. data/sig/test/errors.rbs +52 -0
  244. data/sig/test/guranteed.rbs +9 -0
  245. data/sig/test/type_check.rbs +19 -0
  246. data/sig/test.rbs +82 -0
  247. data/sig/type_alias_dependency.rbs +31 -0
  248. data/sig/type_alias_regularity.rbs +12 -6
  249. data/sig/type_param.rbs +45 -9
  250. data/sig/typename.rbs +8 -5
  251. data/sig/types.rbs +119 -12
  252. data/sig/unit_test/convertibles.rbs +154 -0
  253. data/sig/unit_test/spy.rbs +28 -0
  254. data/sig/unit_test/type_assertions.rbs +194 -0
  255. data/sig/unit_test/with_aliases.rbs +136 -0
  256. data/sig/use_map.rbs +35 -0
  257. data/sig/validator.rbs +12 -5
  258. data/sig/variance_calculator.rbs +3 -1
  259. data/sig/vendorer.rbs +1 -1
  260. data/sig/visitor.rbs +47 -0
  261. data/sig/writer.rbs +6 -2
  262. data/src/constants.c +153 -0
  263. data/src/ruby_objs.c +793 -0
  264. data/stdlib/base64/0/base64.rbs +298 -45
  265. data/stdlib/benchmark/0/benchmark.rbs +12 -3
  266. data/stdlib/bigdecimal/0/big_decimal.rbs +62 -198
  267. data/stdlib/cgi/0/core.rbs +68 -15
  268. data/stdlib/cgi/0/manifest.yaml +1 -0
  269. data/stdlib/coverage/0/coverage.rbs +50 -11
  270. data/stdlib/csv/0/csv.rbs +90 -119
  271. data/stdlib/csv/0/manifest.yaml +1 -0
  272. data/stdlib/date/0/date.rbs +806 -735
  273. data/stdlib/date/0/date_time.rbs +70 -211
  274. data/stdlib/dbm/0/dbm.rbs +0 -2
  275. data/stdlib/delegate/0/delegator.rbs +184 -0
  276. data/stdlib/delegate/0/kernel.rbs +47 -0
  277. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  278. data/stdlib/did_you_mean/0/did_you_mean.rbs +3 -8
  279. data/stdlib/digest/0/digest.rbs +48 -35
  280. data/stdlib/erb/0/erb.rbs +15 -39
  281. data/stdlib/etc/0/etc.rbs +174 -54
  282. data/stdlib/fileutils/0/fileutils.rbs +1234 -385
  283. data/stdlib/forwardable/0/forwardable.rbs +4 -4
  284. data/stdlib/io-console/0/io-console.rbs +82 -17
  285. data/stdlib/ipaddr/0/ipaddr.rbs +11 -6
  286. data/stdlib/json/0/json.rbs +434 -151
  287. data/stdlib/kconv/0/kconv.rbs +166 -0
  288. data/stdlib/logger/0/formatter.rbs +0 -2
  289. data/stdlib/logger/0/log_device.rbs +1 -3
  290. data/stdlib/logger/0/logger.rbs +465 -328
  291. data/stdlib/minitest/0/kernel.rbs +2 -2
  292. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
  293. data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
  294. data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
  295. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
  296. data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
  297. data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
  298. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  299. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  300. data/stdlib/minitest/0/minitest/mock.rbs +9 -5
  301. data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
  302. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
  303. data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
  304. data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
  305. data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
  306. data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
  307. data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
  308. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
  309. data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
  310. data/stdlib/minitest/0/minitest/spec.rbs +1 -1
  311. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
  312. data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
  313. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +7 -7
  314. data/stdlib/minitest/0/minitest/test.rbs +7 -14
  315. data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
  316. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  317. data/stdlib/minitest/0/minitest/unit.rbs +1 -2
  318. data/stdlib/minitest/0/minitest.rbs +41 -892
  319. data/stdlib/monitor/0/monitor.rbs +91 -10
  320. data/stdlib/mutex_m/0/mutex_m.rbs +0 -2
  321. data/stdlib/net-http/0/manifest.yaml +1 -1
  322. data/stdlib/net-http/0/net-http.rbs +3858 -964
  323. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  324. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  325. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  326. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  327. data/stdlib/nkf/0/nkf.rbs +35 -5
  328. data/stdlib/objspace/0/objspace.rbs +40 -18
  329. data/stdlib/observable/0/observable.rbs +217 -0
  330. data/stdlib/open-uri/0/manifest.yaml +4 -0
  331. data/stdlib/open-uri/0/open-uri.rbs +393 -0
  332. data/stdlib/open3/0/open3.rbs +147 -0
  333. data/stdlib/openssl/0/manifest.yaml +1 -0
  334. data/stdlib/openssl/0/openssl.rbs +681 -316
  335. data/stdlib/optparse/0/optparse.rbs +100 -65
  336. data/stdlib/pathname/0/pathname.rbs +24 -15
  337. data/stdlib/pp/0/manifest.yaml +2 -0
  338. data/stdlib/pp/0/pp.rbs +300 -0
  339. data/stdlib/prettyprint/0/prettyprint.rbs +2 -6
  340. data/stdlib/pstore/0/pstore.rbs +370 -156
  341. data/stdlib/psych/0/core_ext.rbs +12 -0
  342. data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
  343. data/stdlib/psych/0/manifest.yaml +3 -0
  344. data/stdlib/psych/0/psych.rbs +402 -0
  345. data/stdlib/{yaml → psych}/0/store.rbs +2 -2
  346. data/stdlib/pty/0/pty.rbs +63 -11
  347. data/stdlib/rdoc/0/code_object.rbs +51 -0
  348. data/stdlib/rdoc/0/comment.rbs +59 -0
  349. data/stdlib/rdoc/0/context.rbs +153 -0
  350. data/stdlib/rdoc/0/markup.rbs +117 -0
  351. data/stdlib/rdoc/0/parser.rbs +56 -0
  352. data/stdlib/rdoc/0/rdoc.rbs +13 -380
  353. data/stdlib/rdoc/0/ri.rbs +17 -0
  354. data/stdlib/rdoc/0/store.rbs +48 -0
  355. data/stdlib/rdoc/0/top_level.rbs +97 -0
  356. data/stdlib/resolv/0/resolv.rbs +16 -79
  357. data/stdlib/ripper/0/ripper.rbs +1648 -0
  358. data/stdlib/securerandom/0/securerandom.rbs +7 -2
  359. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  360. data/stdlib/singleton/0/singleton.rbs +0 -3
  361. data/stdlib/socket/0/addrinfo.rbs +13 -18
  362. data/stdlib/socket/0/basic_socket.rbs +5 -10
  363. data/stdlib/socket/0/ip_socket.rbs +0 -2
  364. data/stdlib/socket/0/socket.rbs +77 -46
  365. data/stdlib/socket/0/tcp_server.rbs +0 -5
  366. data/stdlib/socket/0/tcp_socket.rbs +36 -3
  367. data/stdlib/socket/0/udp_socket.rbs +4 -5
  368. data/stdlib/socket/0/unix_server.rbs +0 -5
  369. data/stdlib/socket/0/unix_socket.rbs +2 -4
  370. data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +188 -107
  371. data/stdlib/strscan/0/string_scanner.rbs +1269 -425
  372. data/stdlib/tempfile/0/tempfile.rbs +224 -61
  373. data/stdlib/time/0/time.rbs +48 -35
  374. data/stdlib/timeout/0/timeout.rbs +17 -8
  375. data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
  376. data/stdlib/tsort/0/tsort.rbs +0 -4
  377. data/stdlib/uri/0/common.rbs +271 -144
  378. data/stdlib/uri/0/file.rbs +5 -0
  379. data/stdlib/uri/0/ftp.rbs +1 -1
  380. data/stdlib/uri/0/generic.rbs +26 -22
  381. data/stdlib/uri/0/http.rbs +4 -4
  382. data/stdlib/uri/0/ldap.rbs +1 -1
  383. data/stdlib/uri/0/mailto.rbs +84 -0
  384. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  385. data/stdlib/yaml/0/manifest.yaml +1 -2
  386. data/stdlib/yaml/0/yaml.rbs +1 -199
  387. data/stdlib/zlib/0/buf_error.rbs +10 -0
  388. data/stdlib/zlib/0/data_error.rbs +10 -0
  389. data/stdlib/zlib/0/deflate.rbs +210 -0
  390. data/stdlib/zlib/0/error.rbs +20 -0
  391. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  392. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  393. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  394. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  395. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  396. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  397. data/stdlib/zlib/0/gzip_writer.rbs +166 -0
  398. data/stdlib/zlib/0/inflate.rbs +180 -0
  399. data/stdlib/zlib/0/mem_error.rbs +10 -0
  400. data/stdlib/zlib/0/need_dict.rbs +13 -0
  401. data/stdlib/zlib/0/stream_end.rbs +11 -0
  402. data/stdlib/zlib/0/stream_error.rbs +11 -0
  403. data/stdlib/zlib/0/version_error.rbs +11 -0
  404. data/stdlib/zlib/0/zlib.rbs +1 -3
  405. data/stdlib/zlib/0/zstream.rbs +200 -0
  406. data/templates/include/rbs/constants.h.erb +20 -0
  407. data/templates/include/rbs/ruby_objs.h.erb +10 -0
  408. data/templates/src/constants.c.erb +36 -0
  409. data/templates/src/ruby_objs.c.erb +27 -0
  410. data/templates/template.rb +122 -0
  411. metadata +136 -36
  412. data/Gemfile +0 -33
  413. data/Gemfile.lock +0 -118
  414. data/core/deprecated.rbs +0 -9
  415. data/ext/rbs_extension/constants.c +0 -135
  416. data/ext/rbs_extension/ruby_objs.c +0 -525
  417. data/ext/rbs_extension/ruby_objs.h +0 -43
  418. data/lib/rbs/constant_table.rb +0 -167
  419. data/lib/rbs/parser_compat/lexer_error.rb +0 -6
  420. data/lib/rbs/parser_compat/located_value.rb +0 -7
  421. data/lib/rbs/parser_compat/semantics_error.rb +0 -6
  422. data/lib/rbs/parser_compat/syntax_error.rb +0 -6
  423. data/lib/rbs/test/spy.rb +0 -6
  424. data/lib/rbs/type_name_resolver.rb +0 -67
  425. data/sig/constant_table.rbs +0 -30
  426. data/sig/shims/abstract_syntax_tree.rbs +0 -25
  427. data/sig/shims/pp.rbs +0 -3
  428. data/sig/shims/ripper.rbs +0 -8
  429. data/sig/shims.rbs +0 -69
  430. data/sig/type_name_resolver.rbs +0 -26
  431. data/stdlib/minitest/0/manifest.yaml +0 -2
  432. data/stdlib/prime/0/integer-extension.rbs +0 -41
  433. data/stdlib/prime/0/manifest.yaml +0 -2
  434. data/stdlib/prime/0/prime.rbs +0 -372
data/core/process.rbs CHANGED
@@ -1,18 +1,403 @@
1
1
  # <!-- rdoc-file=process.c -->
2
- # The module contains several groups of functionality for handling OS processes:
3
- #
4
- # * Low-level property introspection and management of the current process,
5
- # like Process.argv0, Process.pid;
6
- # * Low-level introspection of other processes, like Process.getpgid,
7
- # Process.getpriority;
8
- # * Management of the current process: Process.abort, Process.exit,
9
- # Process.daemon, etc. (for convenience, most of those are also available as
10
- # global functions and module functions of Kernel);
11
- # * Creation and management of child processes: Process.fork, Process.spawn,
12
- # and related methods;
13
- # * Management of low-level system clock: Process.times and
14
- # Process.clock_gettime, which could be important for proper benchmarking
15
- # and other elapsed time measurement tasks.
2
+ # Module `Process` represents a process in the underlying operating system. Its
3
+ # methods support management of the current process and its child processes.
4
+ #
5
+ # ## Process Creation
6
+ #
7
+ # Each of the following methods executes a given command in a new process or
8
+ # subshell, or multiple commands in new processes and/or subshells. The choice
9
+ # of process or subshell depends on the form of the command; see [Argument
10
+ # command_line or exe_path](rdoc-ref:Process@Argument+command_line+or+exe_path).
11
+ #
12
+ # * Process.spawn, Kernel#spawn: Executes the command; returns the new pid
13
+ # without waiting for completion.
14
+ # * Process.exec: Replaces the current process by executing the command.
15
+ #
16
+ # In addition:
17
+ #
18
+ # * Method Kernel#system executes a given command-line (string) in a subshell;
19
+ # returns `true`, `false`, or `nil`.
20
+ # * Method Kernel#` executes a given command-line (string) in a subshell;
21
+ # returns its $stdout string.
22
+ # * Module Open3 supports creating child processes with access to their
23
+ # $stdin, $stdout, and $stderr streams.
24
+ #
25
+ # ### Execution Environment
26
+ #
27
+ # Optional leading argument `env` is a hash of name/value pairs, where each name
28
+ # is a string and each value is a string or `nil`; each name/value pair is added
29
+ # to ENV in the new process.
30
+ #
31
+ # Process.spawn( 'ruby -e "p ENV[\"Foo\"]"')
32
+ # Process.spawn({'Foo' => '0'}, 'ruby -e "p ENV[\"Foo\"]"')
33
+ #
34
+ # Output:
35
+ #
36
+ # "0"
37
+ #
38
+ # The effect is usually similar to that of calling ENV#update with argument
39
+ # `env`, where each named environment variable is created or updated (if the
40
+ # value is non-`nil`), or deleted (if the value is `nil`).
41
+ #
42
+ # However, some modifications to the calling process may remain if the new
43
+ # process fails. For example, hard resource limits are not restored.
44
+ #
45
+ # ### Argument `command_line` or `exe_path`
46
+ #
47
+ # The required string argument is one of the following:
48
+ #
49
+ # * `command_line` if it begins with a shell reserved word or special
50
+ # built-in, or if it contains one or more meta characters.
51
+ # * `exe_path` otherwise.
52
+ #
53
+ # #### Argument `command_line`
54
+ #
55
+ # String argument `command_line` is a command line to be passed to a shell; it
56
+ # must begin with a shell reserved word, begin with a special built-in, or
57
+ # contain meta characters:
58
+ #
59
+ # system('if true; then echo "Foo"; fi') # => true # Shell reserved word.
60
+ # system('exit') # => true # Built-in.
61
+ # system('date > /tmp/date.tmp') # => true # Contains meta character.
62
+ # system('date > /nop/date.tmp') # => false
63
+ # system('date > /nop/date.tmp', exception: true) # Raises RuntimeError.
64
+ #
65
+ # The command line may also contain arguments and options for the command:
66
+ #
67
+ # system('echo "Foo"') # => true
68
+ #
69
+ # Output:
70
+ #
71
+ # Foo
72
+ #
73
+ # See [Execution Shell](rdoc-ref:Process@Execution+Shell) for details about the
74
+ # shell.
75
+ #
76
+ # #### Argument `exe_path`
77
+ #
78
+ # Argument `exe_path` is one of the following:
79
+ #
80
+ # * The string path to an executable file to be called:
81
+ #
82
+ # Example:
83
+ #
84
+ # system('/usr/bin/date') # => true # Path to date on Unix-style system.
85
+ # system('foo') # => nil # Command execlution failed.
86
+ #
87
+ # Output:
88
+ #
89
+ # Thu Aug 31 10:06:48 AM CDT 2023
90
+ #
91
+ # A path or command name containing spaces without arguments cannot be
92
+ # distinguished from `command_line` above, so you must quote or escape the
93
+ # entire command name using a shell in platform dependent manner, or use the
94
+ # array form below.
95
+ #
96
+ # If `exe_path` does not contain any path separator, an executable file is
97
+ # searched from directories specified with the `PATH` environment variable.
98
+ # What the word "executable" means here is depending on platforms.
99
+ #
100
+ # Even if the file considered "executable", its content may not be in proper
101
+ # executable format. In that case, Ruby tries to run it by using `/bin/sh`
102
+ # on a Unix-like system, like system(3) does.
103
+ #
104
+ # File.write('shell_command', 'echo $SHELL', perm: 0o755)
105
+ # system('./shell_command') # prints "/bin/sh" or something.
106
+ #
107
+ # * A 2-element array containing the path to an executable and the string to
108
+ # be used as the name of the executing process:
109
+ #
110
+ # Example:
111
+ #
112
+ # pid = spawn(['sleep', 'Hello!'], '1') # 2-element array.
113
+ # p `ps -p #{pid} -o command=`
114
+ #
115
+ # Output:
116
+ #
117
+ # "Hello! 1\n"
118
+ #
119
+ # ### Arguments `args`
120
+ #
121
+ # If `command_line` does not contain shell meta characters except for spaces and
122
+ # tabs, or `exe_path` is given, Ruby invokes the executable directly. This form
123
+ # does not use the shell:
124
+ #
125
+ # spawn("doesnt_exist") # Raises Errno::ENOENT
126
+ # spawn("doesnt_exist", "\n") # Raises Errno::ENOENT
127
+ #
128
+ # spawn("doesnt_exist\n") # => false
129
+ # # sh: 1: doesnot_exist: not found
130
+ #
131
+ # The error message is from a shell and would vary depending on your system.
132
+ #
133
+ # If one or more `args` is given after `exe_path`, each is an argument or option
134
+ # to be passed to the executable:
135
+ #
136
+ # Example:
137
+ #
138
+ # system('echo', '<', 'C*', '|', '$SHELL', '>') # => true
139
+ #
140
+ # Output:
141
+ #
142
+ # < C* | $SHELL >
143
+ #
144
+ # However, there are exceptions on Windows. See [Execution Shell on
145
+ # Windows](rdoc-ref:Process@Execution+Shell+on+Windows).
146
+ #
147
+ # If you want to invoke a path containing spaces with no arguments without
148
+ # shell, you will need to use a 2-element array `exe_path`.
149
+ #
150
+ # Example:
151
+ #
152
+ # path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
153
+ # spawn(path) # Raises Errno::ENOENT; No such file or directory - /Applications/Google
154
+ # spawn([path] * 2)
155
+ #
156
+ # ### Execution Options
157
+ #
158
+ # Optional trailing argument `options` is a hash of execution options.
159
+ #
160
+ # #### Working Directory (`:chdir`)
161
+ #
162
+ # By default, the working directory for the new process is the same as that of
163
+ # the current process:
164
+ #
165
+ # Dir.chdir('/var')
166
+ # Process.spawn('ruby -e "puts Dir.pwd"')
167
+ #
168
+ # Output:
169
+ #
170
+ # /var
171
+ #
172
+ # Use option `:chdir` to set the working directory for the new process:
173
+ #
174
+ # Process.spawn('ruby -e "puts Dir.pwd"', {chdir: '/tmp'})
175
+ #
176
+ # Output:
177
+ #
178
+ # /tmp
179
+ #
180
+ # The working directory of the current process is not changed:
181
+ #
182
+ # Dir.pwd # => "/var"
183
+ #
184
+ # #### File Redirection (File Descriptor)
185
+ #
186
+ # Use execution options for file redirection in the new process.
187
+ #
188
+ # The key for such an option may be an integer file descriptor (fd), specifying
189
+ # a source, or an array of fds, specifying multiple sources.
190
+ #
191
+ # An integer source fd may be specified as:
192
+ #
193
+ # * *n*: Specifies file descriptor *n*.
194
+ #
195
+ # There are these shorthand symbols for fds:
196
+ #
197
+ # * `:in`: Specifies file descriptor 0 (STDIN).
198
+ # * `:out`: Specifies file descriptor 1 (STDOUT).
199
+ # * `:err`: Specifies file descriptor 2 (STDERR).
200
+ #
201
+ # The value given with a source is one of:
202
+ #
203
+ # * *n*: Redirects to fd *n* in the parent process.
204
+ # * `filepath`: Redirects from or to the file at `filepath` via
205
+ # `open(filepath, mode, 0644)`, where `mode` is `'r'` for source `:in`, or
206
+ # `'w'` for source `:out` or `:err`.
207
+ # * `[filepath]`: Redirects from the file at `filepath` via `open(filepath,
208
+ # 'r', 0644)`.
209
+ # * `[filepath, mode]`: Redirects from or to the file at `filepath` via
210
+ # `open(filepath, mode, 0644)`.
211
+ # * `[filepath, mode, perm]`: Redirects from or to the file at `filepath` via
212
+ # `open(filepath, mode, perm)`.
213
+ # * `[:child, fd]`: Redirects to the redirected `fd`.
214
+ # * `:close`: Closes the file descriptor in child process.
215
+ #
216
+ # See [Access Modes](rdoc-ref:File@Access+Modes) and [File
217
+ # Permissions](rdoc-ref:File@File+Permissions).
218
+ #
219
+ # #### Environment Variables (`:unsetenv_others`)
220
+ #
221
+ # By default, the new process inherits environment variables from the parent
222
+ # process; use execution option key `:unsetenv_others` with value `true` to
223
+ # clear environment variables in the new process.
224
+ #
225
+ # Any changes specified by execution option `env` are made after the new process
226
+ # inherits or clears its environment variables; see [Execution
227
+ # Environment](rdoc-ref:Process@Execution+Environment).
228
+ #
229
+ # #### File-Creation Access (`:umask`)
230
+ #
231
+ # Use execution option `:umask` to set the file-creation access for the new
232
+ # process; see [Access Modes](rdoc-ref:File@Access+Modes):
233
+ #
234
+ # command = 'ruby -e "puts sprintf(\"0%o\", File.umask)"'
235
+ # options = {:umask => 0644}
236
+ # Process.spawn(command, options)
237
+ #
238
+ # Output:
239
+ #
240
+ # 0644
241
+ #
242
+ # #### Process Groups (`:pgroup` and `:new_pgroup`)
243
+ #
244
+ # By default, the new process belongs to the same [process
245
+ # group](https://en.wikipedia.org/wiki/Process_group) as the parent process.
246
+ #
247
+ # To specify a different process group. use execution option `:pgroup` with one
248
+ # of the following values:
249
+ #
250
+ # * `true`: Create a new process group for the new process.
251
+ # * *pgid*: Create the new process in the process group whose id is *pgid*.
252
+ #
253
+ # On Windows only, use execution option `:new_pgroup` with value `true` to
254
+ # create a new process group for the new process.
255
+ #
256
+ # #### Resource Limits
257
+ #
258
+ # Use execution options to set resource limits.
259
+ #
260
+ # The keys for these options are symbols of the form `:rlimit_*resource_name`*,
261
+ # where *resource_name* is the downcased form of one of the string resource
262
+ # names described at method Process.setrlimit. For example, key `:rlimit_cpu`
263
+ # corresponds to resource limit `'CPU'`.
264
+ #
265
+ # The value for such as key is one of:
266
+ #
267
+ # * An integer, specifying both the current and maximum limits.
268
+ # * A 2-element array of integers, specifying the current and maximum limits.
269
+ #
270
+ # #### File Descriptor Inheritance
271
+ #
272
+ # By default, the new process inherits file descriptors from the parent process.
273
+ #
274
+ # Use execution option `:close_others => true` to modify that inheritance by
275
+ # closing non-standard fds (3 and greater) that are not otherwise redirected.
276
+ #
277
+ # ### Execution Shell
278
+ #
279
+ # On a Unix-like system, the shell invoked is `/bin/sh`; the entire string
280
+ # `command_line` is passed as an argument to [shell option
281
+ # -c](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/sh.
282
+ # html).
283
+ #
284
+ # The shell performs normal shell expansion on the command line:
285
+ #
286
+ # Example:
287
+ #
288
+ # system('echo $SHELL: C*') # => true
289
+ #
290
+ # Output:
291
+ #
292
+ # /bin/bash: CONTRIBUTING.md COPYING COPYING.ja
293
+ #
294
+ # #### Execution Shell on Windows
295
+ #
296
+ # On Windows, the shell invoked is determined by environment variable
297
+ # `RUBYSHELL`, if defined, or `COMSPEC` otherwise; the entire string
298
+ # `command_line` is passed as an argument to `-c` option for `RUBYSHELL`, as
299
+ # well as `/bin/sh`, and [/c
300
+ # option](https://learn.microsoft.com/en-us/windows-server/administration/window
301
+ # s-commands/cmd) for `COMSPEC`. The shell is invoked automatically in the
302
+ # following cases:
303
+ #
304
+ # * The command is a built-in of `cmd.exe`, such as `echo`.
305
+ # * The executable file is a batch file; its name ends with `.bat` or `.cmd`.
306
+ #
307
+ # Note that the command will still be invoked as `command_line` form even when
308
+ # called in `exe_path` form, because `cmd.exe` does not accept a script name
309
+ # like `/bin/sh` does but only works with `/c` option.
310
+ #
311
+ # The standard shell `cmd.exe` performs environment variable expansion but does
312
+ # not have globbing functionality:
313
+ #
314
+ # Example:
315
+ #
316
+ # system("echo %COMSPEC%: C*")' # => true
317
+ #
318
+ # Output:
319
+ #
320
+ # C:\WINDOWS\system32\cmd.exe: C*
321
+ #
322
+ # ## What's Here
323
+ #
324
+ # ### Current-Process Getters
325
+ #
326
+ # * ::argv0: Returns the process name as a frozen string.
327
+ # * ::egid: Returns the effective group ID.
328
+ # * ::euid: Returns the effective user ID.
329
+ # * ::getpgrp: Return the process group ID.
330
+ # * ::getrlimit: Returns the resource limit.
331
+ # * ::gid: Returns the (real) group ID.
332
+ # * ::pid: Returns the process ID.
333
+ # * ::ppid: Returns the process ID of the parent process.
334
+ # * ::uid: Returns the (real) user ID.
335
+ #
336
+ # ### Current-Process Setters
337
+ #
338
+ # * ::egid=: Sets the effective group ID.
339
+ # * ::euid=: Sets the effective user ID.
340
+ # * ::gid=: Sets the (real) group ID.
341
+ # * ::setproctitle: Sets the process title.
342
+ # * ::setpgrp: Sets the process group ID of the process to zero.
343
+ # * ::setrlimit: Sets a resource limit.
344
+ # * ::setsid: Establishes the process as a new session and process group
345
+ # leader, with no controlling tty.
346
+ # * ::uid=: Sets the user ID.
347
+ #
348
+ # ### Current-Process Execution
349
+ #
350
+ # * ::abort: Immediately terminates the process.
351
+ # * ::daemon: Detaches the process from its controlling terminal and continues
352
+ # running it in the background as system daemon.
353
+ # * ::exec: Replaces the process by running a given external command.
354
+ # * ::exit: Initiates process termination by raising exception SystemExit
355
+ # (which may be caught).
356
+ # * ::exit!: Immediately exits the process.
357
+ # * ::warmup: Notifies the Ruby virtual machine that the boot sequence for the
358
+ # application is completed, and that the VM may begin optimizing the
359
+ # application.
360
+ #
361
+ # ### Child Processes
362
+ #
363
+ # * ::detach: Guards against a child process becoming a zombie.
364
+ # * ::fork: Creates a child process.
365
+ # * ::kill: Sends a given signal to processes.
366
+ # * ::spawn: Creates a child process.
367
+ # * ::wait, ::waitpid: Waits for a child process to exit; returns its process
368
+ # ID.
369
+ # * ::wait2, ::waitpid2: Waits for a child process to exit; returns its
370
+ # process ID and status.
371
+ # * ::waitall: Waits for all child processes to exit; returns their process
372
+ # IDs and statuses.
373
+ #
374
+ # ### Process Groups
375
+ #
376
+ # * ::getpgid: Returns the process group ID for a process.
377
+ # * ::getpriority: Returns the scheduling priority for a process, process
378
+ # group, or user.
379
+ # * ::getsid: Returns the session ID for a process.
380
+ # * ::groups: Returns an array of the group IDs in the supplemental group
381
+ # access list for this process.
382
+ # * ::groups=: Sets the supplemental group access list to the given array of
383
+ # group IDs.
384
+ # * ::initgroups: Initializes the supplemental group access list.
385
+ # * ::last_status: Returns the status of the last executed child process in
386
+ # the current thread.
387
+ # * ::maxgroups: Returns the maximum number of group IDs allowed in the
388
+ # supplemental group access list.
389
+ # * ::maxgroups=: Sets the maximum number of group IDs allowed in the
390
+ # supplemental group access list.
391
+ # * ::setpgid: Sets the process group ID of a process.
392
+ # * ::setpriority: Sets the scheduling priority for a process, process group,
393
+ # or user.
394
+ #
395
+ # ### Timing
396
+ #
397
+ # * ::clock_getres: Returns the resolution of a system clock.
398
+ # * ::clock_gettime: Returns the time from a system clock.
399
+ # * ::times: Returns a Process::Tms object containing times for the current
400
+ # process and its child processes.
16
401
  #
17
402
  module Process
18
403
  # <!--
@@ -26,6 +411,12 @@ module Process
26
411
  # You can add custom code before and after fork events by overriding this
27
412
  # method.
28
413
  #
414
+ # Note: Process.daemon may be implemented using fork(2) BUT does not go through
415
+ # this method. Thus, depending on your reason to hook into this method, you may
416
+ # also want to hook into that one. See [this
417
+ # issue](https://bugs.ruby-lang.org/issues/18911) for a more detailed discussion
418
+ # of this.
419
+ #
29
420
  def self._fork: () -> Integer
30
421
 
31
422
  # <!--
@@ -42,203 +433,193 @@ module Process
42
433
 
43
434
  # <!--
44
435
  # rdoc-file=process.c
45
- # - Process.clock_getres(clock_id [, unit]) -> number
436
+ # - Process.clock_getres(clock_id, unit = :float_second) -> number
46
437
  # -->
47
- # Returns an estimate of the resolution of a `clock_id` using the POSIX
48
- # `clock_getres()` function.
49
- #
50
- # Note the reported resolution is often inaccurate on most platforms due to
51
- # underlying bugs for this function and therefore the reported resolution often
52
- # differs from the actual resolution of the clock in practice. Inaccurate
53
- # reported resolutions have been observed for various clocks including
54
- # CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW when using Linux, macOS, BSD or AIX
55
- # platforms, when using ARM processors, or when using virtualization.
438
+ # Returns a clock resolution as determined by POSIX function
439
+ # [clock_getres()](https://man7.org/linux/man-pages/man3/clock_getres.3.html):
56
440
  #
57
- # `clock_id` specifies a kind of clock. See the document of
58
- # `Process.clock_gettime` for details. `clock_id` can be a symbol as for
59
- # `Process.clock_gettime`.
441
+ # Process.clock_getres(:CLOCK_REALTIME) # => 1.0e-09
60
442
  #
61
- # If the given `clock_id` is not supported, Errno::EINVAL is raised.
443
+ # See Process.clock_gettime for the values of `clock_id` and `unit`.
62
444
  #
63
- # `unit` specifies the type of the return value. `Process.clock_getres` accepts
64
- # `unit` as `Process.clock_gettime`. The default value, `:float_second`, is also
65
- # the same as `Process.clock_gettime`.
445
+ # Examples:
66
446
  #
67
- # `Process.clock_getres` also accepts `:hertz` as `unit`. `:hertz` means the
68
- # reciprocal of `:float_second`.
447
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) # => 0.001
448
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) # => 1.0e-06
449
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 1.0e-09
450
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :microsecond) # => 0
451
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :millisecond) # => 0
452
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond) # => 1
453
+ # Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :second) # => 0
69
454
  #
70
- # `:hertz` can be used to obtain the exact value of the clock ticks per second
71
- # for the times() function and CLOCKS_PER_SEC for the clock() function.
455
+ # In addition to the values for `unit` supported in Process.clock_gettime, this
456
+ # method supports `:hertz`, the integer number of clock ticks per second (which
457
+ # is the reciprocal of `:float_second`):
72
458
  #
73
- # `Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)` returns
74
- # the clock ticks per second.
459
+ # Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) # => 100.0
460
+ # Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 0.01
75
461
  #
76
- # `Process.clock_getres(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)` returns
77
- # CLOCKS_PER_SEC.
78
- #
79
- # p Process.clock_getres(Process::CLOCK_MONOTONIC)
80
- # #=> 1.0e-09
462
+ # **Accuracy**: Note that the returned resolution may be inaccurate on some
463
+ # platforms due to underlying bugs. Inaccurate resolutions have been reported
464
+ # for various clocks including `:CLOCK_MONOTONIC` and `:CLOCK_MONOTONIC_RAW` on
465
+ # Linux, macOS, BSD or AIX platforms, when using ARM processors, or when using
466
+ # virtualization.
81
467
  #
82
468
  def self.clock_getres: (Symbol | Integer clock_id, ?Symbol unit) -> (Float | Integer)
83
469
 
84
470
  # <!--
85
471
  # rdoc-file=process.c
86
- # - Process.clock_gettime(clock_id [, unit]) -> number
87
- # -->
88
- # Returns a time returned by POSIX clock_gettime() function.
89
- #
90
- # p Process.clock_gettime(Process::CLOCK_MONOTONIC)
91
- # #=> 896053.968060096
92
- #
93
- # `clock_id` specifies a kind of clock. It is specified as a constant which
94
- # begins with `Process::CLOCK_` such as Process::CLOCK_REALTIME and
95
- # Process::CLOCK_MONOTONIC.
96
- #
97
- # The supported constants depends on OS and version. Ruby provides following
98
- # types of `clock_id` if available.
99
- #
100
- # CLOCK_REALTIME
101
- # : SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS
102
- # 10.12, Windows-8/Server-2012
103
- # CLOCK_MONOTONIC
104
- # : SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 3.4, macOS
105
- # 10.12, Windows-2000
106
- # CLOCK_PROCESS_CPUTIME_ID
107
- # : SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3, OpenBSD 5.4, macOS 10.12
108
- # CLOCK_THREAD_CPUTIME_ID
109
- # : SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD 5.4, macOS 10.12
110
- # CLOCK_VIRTUAL
111
- # : FreeBSD 3.0, OpenBSD 2.1
112
- # CLOCK_PROF
113
- # : FreeBSD 3.0, OpenBSD 2.1
114
- # CLOCK_REALTIME_FAST
115
- # : FreeBSD 8.1
116
- # CLOCK_REALTIME_PRECISE
117
- # : FreeBSD 8.1
118
- # CLOCK_REALTIME_COARSE
119
- # : Linux 2.6.32
120
- # CLOCK_REALTIME_ALARM
121
- # : Linux 3.0
122
- # CLOCK_MONOTONIC_FAST
123
- # : FreeBSD 8.1
124
- # CLOCK_MONOTONIC_PRECISE
125
- # : FreeBSD 8.1
126
- # CLOCK_MONOTONIC_COARSE
127
- # : Linux 2.6.32
128
- # CLOCK_MONOTONIC_RAW
129
- # : Linux 2.6.28, macOS 10.12
130
- # CLOCK_MONOTONIC_RAW_APPROX
131
- # : macOS 10.12
132
- # CLOCK_BOOTTIME
133
- # : Linux 2.6.39
134
- # CLOCK_BOOTTIME_ALARM
135
- # : Linux 3.0
136
- # CLOCK_UPTIME
137
- # : FreeBSD 7.0, OpenBSD 5.5
138
- # CLOCK_UPTIME_FAST
139
- # : FreeBSD 8.1
140
- # CLOCK_UPTIME_RAW
141
- # : macOS 10.12
142
- # CLOCK_UPTIME_RAW_APPROX
143
- # : macOS 10.12
144
- # CLOCK_UPTIME_PRECISE
145
- # : FreeBSD 8.1
146
- # CLOCK_SECOND
147
- # : FreeBSD 8.1
148
- # CLOCK_TAI
149
- # : Linux 3.10
150
- #
472
+ # - Process.clock_gettime(clock_id, unit = :float_second) -> number
473
+ # -->
474
+ # Returns a clock time as determined by POSIX function
475
+ # [clock_gettime()](https://man7.org/linux/man-pages/man3/clock_gettime.3.html):
476
+ #
477
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID) # => 198.650379677
478
+ #
479
+ # Argument `clock_id` should be a symbol or a constant that specifies the clock
480
+ # whose time is to be returned; see below.
481
+ #
482
+ # Optional argument `unit` should be a symbol that specifies the unit to be used
483
+ # in the returned clock time; see below.
484
+ #
485
+ # **Argument `clock_id`**
486
+ #
487
+ # Argument `clock_id` specifies the clock whose time is to be returned; it may
488
+ # be a constant such as `Process::CLOCK_REALTIME`, or a symbol shorthand such as
489
+ # `:CLOCK_REALTIME`.
490
+ #
491
+ # The supported clocks depend on the underlying operating system; this method
492
+ # supports the following clocks on the indicated platforms (raises Errno::EINVAL
493
+ # if called with an unsupported clock):
494
+ #
495
+ # * `:CLOCK_BOOTTIME`: Linux 2.6.39.
496
+ # * `:CLOCK_BOOTTIME_ALARM`: Linux 3.0.
497
+ # * `:CLOCK_MONOTONIC`: SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0,
498
+ # OpenBSD 3.4, macOS 10.12, Windows-2000.
499
+ # * `:CLOCK_MONOTONIC_COARSE`: Linux 2.6.32.
500
+ # * `:CLOCK_MONOTONIC_FAST`: FreeBSD 8.1.
501
+ # * `:CLOCK_MONOTONIC_PRECISE`: FreeBSD 8.1.
502
+ # * `:CLOCK_MONOTONIC_RAW`: Linux 2.6.28, macOS 10.12.
503
+ # * `:CLOCK_MONOTONIC_RAW_APPROX`: macOS 10.12.
504
+ # * `:CLOCK_PROCESS_CPUTIME_ID`: SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3,
505
+ # OpenBSD 5.4, macOS 10.12.
506
+ # * `:CLOCK_PROF`: FreeBSD 3.0, OpenBSD 2.1.
507
+ # * `:CLOCK_REALTIME`: SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0,
508
+ # OpenBSD 2.1, macOS 10.12, Windows-8/Server-2012. Time.now is recommended
509
+ # over +:CLOCK_REALTIME:.
510
+ # * `:CLOCK_REALTIME_ALARM`: Linux 3.0.
511
+ # * `:CLOCK_REALTIME_COARSE`: Linux 2.6.32.
512
+ # * `:CLOCK_REALTIME_FAST`: FreeBSD 8.1.
513
+ # * `:CLOCK_REALTIME_PRECISE`: FreeBSD 8.1.
514
+ # * `:CLOCK_SECOND`: FreeBSD 8.1.
515
+ # * `:CLOCK_TAI`: Linux 3.10.
516
+ # * `:CLOCK_THREAD_CPUTIME_ID`: SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD
517
+ # 5.4, macOS 10.12.
518
+ # * `:CLOCK_UPTIME`: FreeBSD 7.0, OpenBSD 5.5.
519
+ # * `:CLOCK_UPTIME_FAST`: FreeBSD 8.1.
520
+ # * `:CLOCK_UPTIME_PRECISE`: FreeBSD 8.1.
521
+ # * `:CLOCK_UPTIME_RAW`: macOS 10.12.
522
+ # * `:CLOCK_UPTIME_RAW_APPROX`: macOS 10.12.
523
+ # * `:CLOCK_VIRTUAL`: FreeBSD 3.0, OpenBSD 2.1.
151
524
  #
152
525
  # Note that SUS stands for Single Unix Specification. SUS contains POSIX and
153
- # clock_gettime is defined in the POSIX part. SUS defines CLOCK_REALTIME
154
- # mandatory but CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID and
155
- # CLOCK_THREAD_CPUTIME_ID are optional.
156
- #
157
- # Also, several symbols are accepted as `clock_id`. There are emulations for
158
- # clock_gettime().
159
- #
160
- # For example, Process::CLOCK_REALTIME is defined as
161
- # `:GETTIMEOFDAY_BASED_CLOCK_REALTIME` when clock_gettime() is not available.
162
- #
163
- # Emulations for `CLOCK_REALTIME`:
164
- # :GETTIMEOFDAY_BASED_CLOCK_REALTIME
165
- # : Use gettimeofday() defined by SUS. (SUSv4 obsoleted it, though.) The
166
- # resolution is 1 microsecond.
167
- # :TIME_BASED_CLOCK_REALTIME
168
- # : Use time() defined by ISO C. The resolution is 1 second.
169
- #
170
- #
171
- # Emulations for `CLOCK_MONOTONIC`:
172
- # :MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
173
- # : Use mach_absolute_time(), available on Darwin. The resolution is CPU
174
- # dependent.
175
- # :TIMES_BASED_CLOCK_MONOTONIC
176
- # : Use the result value of times() defined by POSIX. POSIX defines it as
177
- # "times() shall return the elapsed real time, in clock ticks, since an
178
- # arbitrary point in the past (for example, system start-up time)". For
179
- # example, GNU/Linux returns a value based on jiffies and it is monotonic.
180
- # However, 4.4BSD uses gettimeofday() and it is not monotonic. (FreeBSD uses
181
- # clock_gettime(CLOCK_MONOTONIC) instead, though.) The resolution is the
182
- # clock tick. "getconf CLK_TCK" command shows the clock ticks per second.
183
- # (The clock ticks per second is defined by HZ macro in older systems.) If
184
- # it is 100 and clock_t is 32 bits integer type, the resolution is 10
185
- # millisecond and cannot represent over 497 days.
186
- #
187
- #
188
- # Emulations for `CLOCK_PROCESS_CPUTIME_ID`:
189
- # :GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
190
- # : Use getrusage() defined by SUS. getrusage() is used with RUSAGE_SELF to
191
- # obtain the time only for the calling process (excluding the time for child
192
- # processes). The result is addition of user time (ru_utime) and system time
193
- # (ru_stime). The resolution is 1 microsecond.
194
- # :TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
195
- # : Use times() defined by POSIX. The result is addition of user time
196
- # (tms_utime) and system time (tms_stime). tms_cutime and tms_cstime are
197
- # ignored to exclude the time for child processes. The resolution is the
198
- # clock tick. "getconf CLK_TCK" command shows the clock ticks per second.
199
- # (The clock ticks per second is defined by HZ macro in older systems.) If
200
- # it is 100, the resolution is 10 millisecond.
201
- # :CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
202
- # : Use clock() defined by ISO C. The resolution is 1/CLOCKS_PER_SEC.
203
- # CLOCKS_PER_SEC is the C-level macro defined by time.h. SUS defines
204
- # CLOCKS_PER_SEC is 1000000. Non-Unix systems may define it a different
205
- # value, though. If CLOCKS_PER_SEC is 1000000 as SUS, the resolution is 1
206
- # microsecond. If CLOCKS_PER_SEC is 1000000 and clock_t is 32 bits integer
207
- # type, it cannot represent over 72 minutes.
208
- #
209
- #
210
- # If the given `clock_id` is not supported, Errno::EINVAL is raised.
211
- #
212
- # `unit` specifies a type of the return value.
213
- #
214
- # :float_second
215
- # : number of seconds as a float (default)
216
- # :float_millisecond
217
- # : number of milliseconds as a float
218
- # :float_microsecond
219
- # : number of microseconds as a float
220
- # :second
221
- # : number of seconds as an integer
222
- # :millisecond
223
- # : number of milliseconds as an integer
224
- # :microsecond
225
- # : number of microseconds as an integer
226
- # :nanosecond
227
- # : number of nanoseconds as an integer
228
- #
526
+ # clock_gettime is defined in the POSIX part. SUS defines `:CLOCK_REALTIME` as
527
+ # mandatory but `:CLOCK_MONOTONIC`, `:CLOCK_PROCESS_CPUTIME_ID`, and
528
+ # `:CLOCK_THREAD_CPUTIME_ID` are optional.
529
+ #
530
+ # Certain emulations are used when the given `clock_id` is not supported
531
+ # directly:
532
+ #
533
+ # * Emulations for `:CLOCK_REALTIME`:
534
+ #
535
+ # * `:GETTIMEOFDAY_BASED_CLOCK_REALTIME`: Use gettimeofday() defined by
536
+ # SUS (deprecated in SUSv4). The resolution is 1 microsecond.
537
+ # * `:TIME_BASED_CLOCK_REALTIME`: Use time() defined by ISO C. The
538
+ # resolution is 1 second.
539
+ #
540
+ # * Emulations for `:CLOCK_MONOTONIC`:
541
+ #
542
+ # * `:MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC`: Use mach_absolute_time(),
543
+ # available on Darwin. The resolution is CPU dependent.
544
+ # * `:TIMES_BASED_CLOCK_MONOTONIC`: Use the result value of times()
545
+ # defined by POSIX, thus:
546
+ # > Upon successful completion, times() shall return the elapsed real
547
+ # time, in clock ticks, since an arbitrary point in the past (for
548
+ # example, system start-up time).
549
+ #
550
+ # > For example, GNU/Linux returns a value based on jiffies and it is
551
+ # monotonic. However, 4.4BSD uses gettimeofday() and it is not
552
+ # monotonic. (FreeBSD uses `:CLOCK_MONOTONIC` instead, though.)
553
+ #
554
+ # The resolution is the clock tick. "getconf CLK_TCK" command shows the
555
+ # clock ticks per second. (The clock ticks-per-second is defined by HZ
556
+ # macro in older systems.) If it is 100 and clock_t is 32 bits integer
557
+ # type, the resolution is 10 millisecond and cannot represent over 497
558
+ # days.
559
+ #
560
+ # * Emulations for `:CLOCK_PROCESS_CPUTIME_ID`:
561
+ #
562
+ # * `:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID`: Use getrusage() defined
563
+ # by SUS. getrusage() is used with RUSAGE_SELF to obtain the time only
564
+ # for the calling process (excluding the time for child processes). The
565
+ # result is addition of user time (ru_utime) and system time (ru_stime).
566
+ # The resolution is 1 microsecond.
567
+ # * `:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID`: Use times() defined by POSIX.
568
+ # The result is addition of user time (tms_utime) and system time
569
+ # (tms_stime). tms_cutime and tms_cstime are ignored to exclude the time
570
+ # for child processes. The resolution is the clock tick. "getconf
571
+ # CLK_TCK" command shows the clock ticks per second. (The clock ticks
572
+ # per second is defined by HZ macro in older systems.) If it is 100, the
573
+ # resolution is 10 millisecond.
574
+ # * `:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID`: Use clock() defined by ISO C.
575
+ # The resolution is `1/CLOCKS_PER_SEC`. `CLOCKS_PER_SEC` is the C-level
576
+ # macro defined by time.h. SUS defines `CLOCKS_PER_SEC` as 1000000;
577
+ # other systems may define it differently. If `CLOCKS_PER_SEC` is
578
+ # 1000000 (as in SUS), the resolution is 1 microsecond. If
579
+ # `CLOCKS_PER_SEC` is 1000000 and clock_t is a 32-bit integer type, it
580
+ # cannot represent over 72 minutes.
581
+ #
582
+ # **Argument `unit`**
583
+ #
584
+ # Optional argument `unit` (default `:float_second`) specifies the unit for the
585
+ # returned value.
586
+ #
587
+ # * `:float_microsecond`: Number of microseconds as a float.
588
+ # * `:float_millisecond`: Number of milliseconds as a float.
589
+ # * `:float_second`: Number of seconds as a float.
590
+ # * `:microsecond`: Number of microseconds as an integer.
591
+ # * `:millisecond`: Number of milliseconds as an integer.
592
+ # * `:nanosecond`: Number of nanoseconds as an integer.
593
+ # * `::second`: Number of seconds as an integer.
594
+ #
595
+ # Examples:
596
+ #
597
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond)
598
+ # # => 203605054.825
599
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond)
600
+ # # => 203643.696848
601
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_second)
602
+ # # => 203.762181929
603
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :microsecond)
604
+ # # => 204123212
605
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :millisecond)
606
+ # # => 204298
607
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond)
608
+ # # => 204602286036
609
+ # Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :second)
610
+ # # => 204
229
611
  #
230
612
  # The underlying function, clock_gettime(), returns a number of nanoseconds.
231
613
  # Float object (IEEE 754 double) is not enough to represent the return value for
232
- # CLOCK_REALTIME. If the exact nanoseconds value is required, use `:nanoseconds`
233
- # as the `unit`.
614
+ # `:CLOCK_REALTIME`. If the exact nanoseconds value is required, use
615
+ # `:nanosecond` as the `unit`.
234
616
  #
235
- # The origin (zero) of the returned value varies. For example, system start up
236
- # time, process start up time, the Epoch, etc.
617
+ # The origin (time zero) of the returned value is system-dependent, and may be,
618
+ # for example, system start up time, process start up time, the Epoch, etc.
237
619
  #
238
- # The origin in CLOCK_REALTIME is defined as the Epoch (1970-01-01 00:00:00
239
- # UTC). But some systems count leap seconds and others doesn't. So the result
240
- # can be interpreted differently across systems. Time.now is recommended over
241
- # CLOCK_REALTIME.
620
+ # The origin in `:CLOCK_REALTIME` is defined as the Epoch: `1970-01-01 00:00:00
621
+ # UTC`; some systems count leap seconds and others don't, so the result may vary
622
+ # across systems.
242
623
  #
243
624
  def self.clock_gettime: (Symbol | Integer clock_id) -> Float
244
625
  | (Symbol | Integer clock_id, :float_second | :float_millisecond | :float_microsecond unit) -> Float
@@ -246,210 +627,233 @@ module Process
246
627
 
247
628
  # <!--
248
629
  # rdoc-file=process.c
249
- # - Process.daemon() -> 0
250
- # - Process.daemon(nochdir=nil,noclose=nil) -> 0
630
+ # - Process.daemon(nochdir = nil, noclose = nil) -> 0
251
631
  # -->
252
- # Detach the process from controlling terminal and run in the background as
253
- # system daemon. Unless the argument nochdir is true (i.e. non false), it
254
- # changes the current working directory to the root ("/"). Unless the argument
255
- # noclose is true, daemon() will redirect standard input, standard output and
256
- # standard error to /dev/null. Return zero on success, or raise one of Errno::*.
632
+ # Detaches the current process from its controlling terminal and runs it in the
633
+ # background as system daemon; returns zero.
634
+ #
635
+ # By default:
636
+ #
637
+ # * Changes the current working directory to the root directory.
638
+ # * Redirects $stdin, $stdout, and $stderr to the null device.
639
+ #
640
+ # If optional argument `nochdir` is `true`, does not change the current working
641
+ # directory.
642
+ #
643
+ # If optional argument `noclose` is `true`, does not redirect $stdin, $stdout,
644
+ # or $stderr.
257
645
  #
258
646
  def self.daemon: (?untyped nochdir, ?untyped noclose) -> Integer
259
647
 
260
648
  # <!--
261
649
  # rdoc-file=process.c
262
- # - Process.detach(pid) -> thread
650
+ # - Process.detach(pid) -> thread
263
651
  # -->
264
- # Some operating systems retain the status of terminated child processes until
265
- # the parent collects that status (normally using some variant of `wait()`). If
266
- # the parent never collects this status, the child stays around as a *zombie*
267
- # process. Process::detach prevents this by setting up a separate Ruby thread
268
- # whose sole job is to reap the status of the process *pid* when it terminates.
269
- # Use #detach only when you do not intend to explicitly wait for the child to
270
- # terminate.
652
+ # Avoids the potential for a child process to become a [zombie
653
+ # process](https://en.wikipedia.org/wiki/Zombie_process). Process.detach
654
+ # prevents this by setting up a separate Ruby thread whose sole job is to reap
655
+ # the status of the process *pid* when it terminates.
271
656
  #
272
- # The waiting thread returns the exit status of the detached process when it
273
- # terminates, so you can use Thread#join to know the result. If specified *pid*
274
- # is not a valid child process ID, the thread returns `nil` immediately.
657
+ # This method is needed only when the parent process will never wait for the
658
+ # child process.
275
659
  #
276
- # The waiting thread has #pid method which returns the pid.
660
+ # This example does not reap the second child process; that process appears as a
661
+ # zombie in the process status (`ps`) output:
277
662
  #
278
- # In this first example, we don't reap the first child process, so it appears as
279
- # a zombie in the process status display.
663
+ # pid = Process.spawn('ruby', '-e', 'exit 13') # => 312691
664
+ # sleep(1)
665
+ # # Find zombies.
666
+ # system("ps -ho pid,state -p #{pid}")
280
667
  #
281
- # p1 = fork { sleep 0.1 }
282
- # p2 = fork { sleep 0.2 }
283
- # Process.waitpid(p2)
284
- # sleep 2
285
- # system("ps -ho pid,state -p #{p1}")
668
+ # Output:
286
669
  #
287
- # *produces:*
670
+ # 312716 Z
288
671
  #
289
- # 27389 Z
672
+ # This example also does not reap the second child process, but it does detach
673
+ # the process so that it does not become a zombie:
290
674
  #
291
- # In the next example, Process::detach is used to reap the child automatically.
675
+ # pid = Process.spawn('ruby', '-e', 'exit 13') # => 313213
676
+ # thread = Process.detach(pid)
677
+ # sleep(1)
678
+ # # => #<Process::Waiter:0x00007f038f48b838 run>
679
+ # system("ps -ho pid,state -p #{pid}") # Finds no zombies.
292
680
  #
293
- # p1 = fork { sleep 0.1 }
294
- # p2 = fork { sleep 0.2 }
295
- # Process.detach(p1)
296
- # Process.waitpid(p2)
297
- # sleep 2
298
- # system("ps -ho pid,state -p #{p1}")
681
+ # The waiting thread can return the pid of the detached child process:
299
682
  #
300
- # *(produces no output)*
683
+ # thread.join.pid # => 313262
301
684
  #
302
- def self.detach: (Integer pid) -> Thread
685
+ def self.detach: (Integer pid) -> Process::Waiter
303
686
 
304
687
  # <!--
305
688
  # rdoc-file=process.c
306
- # - Process.egid -> integer
307
- # - Process::GID.eid -> integer
308
- # - Process::Sys.geteid -> integer
689
+ # - Process.egid -> integer
690
+ # - Process::GID.eid -> integer
691
+ # - Process::Sys.geteid -> integer
309
692
  # -->
310
- # Returns the effective group ID for this process. Not available on all
311
- # platforms.
693
+ # Returns the effective group ID for the current process:
312
694
  #
313
- # Process.egid #=> 500
695
+ # Process.egid # => 500
696
+ #
697
+ # Not available on all platforms.
314
698
  #
315
699
  def self.egid: () -> Integer
316
700
 
317
701
  # <!--
318
702
  # rdoc-file=process.c
319
- # - Process.egid = integer -> integer
703
+ # - Process.egid = new_egid -> new_egid
320
704
  # -->
321
- # Sets the effective group ID for this process. Not available on all platforms.
705
+ # Sets the effective group ID for the current process.
706
+ #
707
+ # Not available on all platforms.
322
708
  #
323
709
  def self.egid=: (Integer arg0) -> Integer
324
710
 
325
711
  # <!--
326
712
  # rdoc-file=process.c
327
- # - Process.euid -> integer
328
- # - Process::UID.eid -> integer
329
- # - Process::Sys.geteuid -> integer
713
+ # - Process.euid -> integer
714
+ # - Process::UID.eid -> integer
715
+ # - Process::Sys.geteuid -> integer
330
716
  # -->
331
- # Returns the effective user ID for this process.
717
+ # Returns the effective user ID for the current process.
332
718
  #
333
- # Process.euid #=> 501
719
+ # Process.euid # => 501
334
720
  #
335
721
  def self.euid: () -> Integer
336
722
 
337
723
  # <!--
338
724
  # rdoc-file=process.c
339
- # - Process.euid= user
725
+ # - Process.euid = new_euid -> new_euid
340
726
  # -->
341
- # Sets the effective user ID for this process. Not available on all platforms.
727
+ # Sets the effective user ID for the current process.
728
+ #
729
+ # Not available on all platforms.
342
730
  #
343
731
  def self.euid=: (Integer arg0) -> Integer
344
732
 
345
733
  # <!--
346
734
  # rdoc-file=process.c
347
- # - Process.getpgid(pid) -> integer
735
+ # - Process.getpgid(pid) -> integer
348
736
  # -->
349
- # Returns the process group ID for the given process id. Not available on all
350
- # platforms.
737
+ # Returns the process group ID for the given process ID +pid+:
738
+ #
739
+ # Process.getpgid(Process.ppid) # => 25527
351
740
  #
352
- # Process.getpgid(Process.ppid()) #=> 25527
741
+ # Not available on all platforms.
353
742
  #
354
743
  def self.getpgid: (Integer pid) -> Integer
355
744
 
356
745
  # <!--
357
746
  # rdoc-file=process.c
358
- # - Process.getpgrp -> integer
747
+ # - Process.getpgrp -> integer
359
748
  # -->
360
- # Returns the process group ID for this process. Not available on all platforms.
749
+ # Returns the process group ID for the current process:
361
750
  #
362
- # Process.getpgid(0) #=> 25527
363
- # Process.getpgrp #=> 25527
751
+ # Process.getpgid(0) # => 25527
752
+ # Process.getpgrp # => 25527
364
753
  #
365
754
  def self.getpgrp: () -> Integer
366
755
 
367
756
  # <!--
368
757
  # rdoc-file=process.c
369
- # - Process.getpriority(kind, integer) -> integer
758
+ # - Process.getpriority(kind, id) -> integer
370
759
  # -->
371
- # Gets the scheduling priority for specified process, process group, or user.
372
- # *kind* indicates the kind of entity to find: one of Process::PRIO_PGRP,
373
- # Process::PRIO_USER, or Process::PRIO_PROCESS. *integer* is an id indicating
374
- # the particular process, process group, or user (an id of 0 means *current*).
375
- # Lower priorities are more favorable for scheduling. Not available on all
376
- # platforms.
760
+ # Returns the scheduling priority for specified process, process group, or user.
761
+ #
762
+ # Argument `kind` is one of:
763
+ #
764
+ # * Process::PRIO_PROCESS: return priority for process.
765
+ # * Process::PRIO_PGRP: return priority for process group.
766
+ # * Process::PRIO_USER: return priority for user.
377
767
  #
378
- # Process.getpriority(Process::PRIO_USER, 0) #=> 19
379
- # Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19
768
+ # Argument `id` is the ID for the process, process group, or user; zero
769
+ # specified the current ID for `kind`.
770
+ #
771
+ # Examples:
772
+ #
773
+ # Process.getpriority(Process::PRIO_USER, 0) # => 19
774
+ # Process.getpriority(Process::PRIO_PROCESS, 0) # => 19
775
+ #
776
+ # Not available on all platforms.
380
777
  #
381
778
  def self.getpriority: (Integer kind, Integer arg0) -> Integer
382
779
 
383
780
  # <!--
384
781
  # rdoc-file=process.c
385
- # - Process.getrlimit(resource) -> [cur_limit, max_limit]
782
+ # - Process.getrlimit(resource) -> [cur_limit, max_limit]
386
783
  # -->
387
- # Gets the resource limit of the process. *cur_limit* means current (soft) limit
388
- # and *max_limit* means maximum (hard) limit.
784
+ # Returns a 2-element array of the current (soft) limit and maximum (hard) limit
785
+ # for the given `resource`.
786
+ #
787
+ # Argument `resource` specifies the resource whose limits are to be returned;
788
+ # see Process.setrlimit.
789
+ #
790
+ # Each of the returned values `cur_limit` and `max_limit` is an integer; see
791
+ # Process.setrlimit.
792
+ #
793
+ # Example:
389
794
  #
390
- # *resource* indicates the kind of resource to limit. It is specified as a
391
- # symbol such as `:CORE`, a string such as `"CORE"` or a constant such as
392
- # Process::RLIMIT_CORE. See Process.setrlimit for details.
795
+ # Process.getrlimit(:CORE) # => [0, 18446744073709551615]
393
796
  #
394
- # *cur_limit* and *max_limit* may be Process::RLIM_INFINITY,
395
- # Process::RLIM_SAVED_MAX or Process::RLIM_SAVED_CUR. See Process.setrlimit and
396
- # the system getrlimit(2) manual for details.
797
+ # See Process.setrlimit.
397
798
  #
398
- def self.getrlimit: (Symbol | String | Integer resource) -> [ Integer, Integer ]
799
+ # Not available on all platforms.
800
+ #
801
+ def self.getrlimit: (interned | Integer resource) -> [ Integer, Integer ]
399
802
 
400
803
  # <!--
401
804
  # rdoc-file=process.c
402
- # - Process.getsid() -> integer
403
- # - Process.getsid(pid) -> integer
805
+ # - Process.getsid(pid = nil) -> integer
404
806
  # -->
405
- # Returns the session ID for the given process id. If not given, return current
406
- # process sid. Not available on all platforms.
807
+ # Returns the session ID of the given process ID `pid`, or of the current
808
+ # process if not given:
407
809
  #
408
- # Process.getsid() #=> 27422
409
- # Process.getsid(0) #=> 27422
410
- # Process.getsid(Process.pid()) #=> 27422
810
+ # Process.getsid # => 27422
811
+ # Process.getsid(0) # => 27422
812
+ # Process.getsid(Process.pid()) # => 27422
813
+ #
814
+ # Not available on all platforms.
411
815
  #
412
816
  def self.getsid: (?Integer pid) -> Integer
413
817
 
414
818
  # <!--
415
819
  # rdoc-file=process.c
416
- # - Process.gid -> integer
417
- # - Process::GID.rid -> integer
418
- # - Process::Sys.getgid -> integer
820
+ # - Process.gid -> integer
821
+ # - Process::GID.rid -> integer
822
+ # - Process::Sys.getgid -> integer
419
823
  # -->
420
- # Returns the (real) group ID for this process.
824
+ # Returns the (real) group ID for the current process:
421
825
  #
422
- # Process.gid #=> 500
826
+ # Process.gid # => 1000
423
827
  #
424
828
  def self.gid: () -> Integer
425
829
 
426
830
  # <!--
427
831
  # rdoc-file=process.c
428
- # - Process.gid= integer -> integer
832
+ # - Process.gid = new_gid -> new_gid
429
833
  # -->
430
- # Sets the group ID for this process.
834
+ # Sets the group ID for the current process to `new_gid`:
835
+ #
836
+ # Process.gid = 1000 # => 1000
431
837
  #
432
838
  def self.gid=: (Integer arg0) -> Integer
433
839
 
434
840
  # <!--
435
841
  # rdoc-file=process.c
436
- # - Process.groups -> array
842
+ # - Process.groups -> array
437
843
  # -->
438
- # Get an Array of the group IDs in the supplemental group access list for this
439
- # process.
440
- #
441
- # Process.groups #=> [27, 6, 10, 11]
844
+ # Returns an array of the group IDs in the supplemental group access list for
845
+ # the current process:
442
846
  #
443
- # Note that this method is just a wrapper of getgroups(2). This means that the
444
- # following characteristics of the result completely depend on your system:
847
+ # Process.groups # => [4, 24, 27, 30, 46, 122, 135, 136, 1000]
445
848
  #
446
- # * the result is sorted
447
- # * the result includes effective GIDs
448
- # * the result does not include duplicated GIDs
849
+ # These properties of the returned array are system-dependent:
449
850
  #
851
+ # * Whether (and how) the array is sorted.
852
+ # * Whether the array includes effective group IDs.
853
+ # * Whether the array includes duplicate group IDs.
854
+ # * Whether the array size exceeds the value of Process.maxgroups.
450
855
  #
451
- # You can make sure to get a sorted unique GID list of the current process by
452
- # this expression:
856
+ # Use this call to get a sorted and unique array:
453
857
  #
454
858
  # Process.groups.uniq.sort
455
859
  #
@@ -457,132 +861,179 @@ module Process
457
861
 
458
862
  # <!--
459
863
  # rdoc-file=process.c
460
- # - Process.groups= array -> array
864
+ # - Process.groups = new_groups -> new_groups
461
865
  # -->
462
- # Set the supplemental group access list to the given Array of group IDs.
866
+ # Sets the supplemental group access list to the given array of group IDs.
463
867
  #
464
- # Process.groups #=> [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
465
- # Process.groups = [27, 6, 10, 11] #=> [27, 6, 10, 11]
466
- # Process.groups #=> [27, 6, 10, 11]
868
+ # Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
869
+ # Process.groups = [27, 6, 10, 11] # => [27, 6, 10, 11]
870
+ # Process.groups # => [27, 6, 10, 11]
467
871
  #
468
872
  def self.groups=: (::Array[Integer] arg0) -> ::Array[Integer]
469
873
 
470
874
  # <!--
471
875
  # rdoc-file=process.c
472
- # - Process.initgroups(username, gid) -> array
876
+ # - Process.initgroups(username, gid) -> array
473
877
  # -->
474
- # Initializes the supplemental group access list by reading the system group
475
- # database and using all groups of which the given user is a member. The group
476
- # with the specified *gid* is also added to the list. Returns the resulting
477
- # Array of the gids of all the groups in the supplementary group access list.
478
- # Not available on all platforms.
878
+ # Sets the supplemental group access list; the new list includes:
879
+ #
880
+ # * The group IDs of those groups to which the user given by `username`
881
+ # belongs.
882
+ # * The group ID `gid`.
479
883
  #
480
- # Process.groups #=> [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
481
- # Process.initgroups( "mgranger", 30 ) #=> [30, 6, 10, 11]
482
- # Process.groups #=> [30, 6, 10, 11]
884
+ # Example:
885
+ #
886
+ # Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
887
+ # Process.initgroups('me', 30) # => [30, 6, 10, 11]
888
+ # Process.groups # => [30, 6, 10, 11]
889
+ #
890
+ # Not available on all platforms.
483
891
  #
484
892
  def self.initgroups: (String username, Integer gid) -> ::Array[Integer]
485
893
 
486
894
  # <!--
487
895
  # rdoc-file=process.c
488
- # - Process.kill(signal, pid, ...) -> integer
896
+ # - Process.kill(signal, *ids) -> count
489
897
  # -->
490
- # Sends the given signal to the specified process id(s) if *pid* is positive. If
491
- # *pid* is zero, *signal* is sent to all processes whose group ID is equal to
492
- # the group ID of the process. If *pid* is negative, results are dependent on
493
- # the operating system. *signal* may be an integer signal number or a POSIX
494
- # signal name (either with or without a `SIG` prefix). If *signal* is negative
495
- # (or starts with a minus sign), kills process groups instead of processes. Not
496
- # all signals are available on all platforms. The keys and values of Signal.list
497
- # are known signal names and numbers, respectively.
898
+ # Sends a signal to each process specified by `ids` (which must specify at least
899
+ # one ID); returns the count of signals sent.
900
+ #
901
+ # For each given `id`, if `id` is:
902
+ #
903
+ # * Positive, sends the signal to the process whose process ID is `id`.
904
+ # * Zero, send the signal to all processes in the current process group.
905
+ # * Negative, sends the signal to a system-dependent collection of processes.
906
+ #
907
+ # Argument `signal` specifies the signal to be sent; the argument may be:
908
+ #
909
+ # * An integer signal number: e.g., `-29`, `0`, `29`.
910
+ # * A signal name (string), with or without leading `'SIG'`, and with or
911
+ # without a further prefixed minus sign (`'-'`): e.g.:
912
+ #
913
+ # * `'SIGPOLL'`.
914
+ # * `'POLL'`,
915
+ # * `'-SIGPOLL'`.
916
+ # * `'-POLL'`.
917
+ #
918
+ # * A signal symbol, with or without leading `'SIG'`, and with or without a
919
+ # further prefixed minus sign (`'-'`): e.g.:
920
+ #
921
+ # * `:SIGPOLL`.
922
+ # * `:POLL`.
923
+ # * `:'-SIGPOLL'`.
924
+ # * `:'-POLL'`.
925
+ #
926
+ # If `signal` is:
927
+ #
928
+ # * A non-negative integer, or a signal name or symbol without prefixed `'-'`,
929
+ # each process with process ID `id` is signalled.
930
+ # * A negative integer, or a signal name or symbol with prefixed `'-'`, each
931
+ # process group with group ID `id` is signalled.
932
+ #
933
+ # Use method Signal.list to see which signals are supported by Ruby on the
934
+ # underlying platform; the method returns a hash of the string names and
935
+ # non-negative integer values of the supported signals. The size and content of
936
+ # the returned hash varies widely among platforms.
937
+ #
938
+ # Additionally, signal `0` is useful to determine if the process exists.
939
+ #
940
+ # Example:
498
941
  #
499
942
  # pid = fork do
500
- # Signal.trap("HUP") { puts "Ouch!"; exit }
501
- # # ... do some work ...
943
+ # Signal.trap('HUP') { puts 'Ouch!'; exit }
944
+ # # ... do some work ...
502
945
  # end
503
946
  # # ...
504
- # Process.kill("HUP", pid)
947
+ # Process.kill('HUP', pid)
505
948
  # Process.wait
506
949
  #
507
- # *produces:*
950
+ # Output:
508
951
  #
509
952
  # Ouch!
510
953
  #
511
- # If *signal* is an integer but wrong for signal, Errno::EINVAL or RangeError
512
- # will be raised. Otherwise unless *signal* is a String or a Symbol, and a
513
- # known signal name, ArgumentError will be raised.
954
+ # Exceptions:
955
+ #
956
+ # * Raises Errno::EINVAL or RangeError if `signal` is an integer but invalid.
957
+ # * Raises ArgumentError if `signal` is a string or symbol but invalid.
958
+ # * Raises Errno::ESRCH or RangeError if one of `ids` is invalid.
959
+ # * Raises Errno::EPERM if needed permissions are not in force.
514
960
  #
515
- # Also, Errno::ESRCH or RangeError for invalid *pid*, Errno::EPERM when failed
516
- # because of no privilege, will be raised. In these cases, signals may have
517
- # been sent to preceding processes.
961
+ # In the last two cases, signals may have been sent to some processes.
518
962
  #
519
- def self.kill: (Integer | Symbol | String signal, *Integer pids) -> Integer
963
+ def self.kill: (Integer | interned signal, *Integer pids) -> Integer
520
964
 
521
965
  # <!--
522
966
  # rdoc-file=process.c
523
- # - Process.maxgroups -> integer
967
+ # - Process.maxgroups -> integer
524
968
  # -->
525
- # Returns the maximum number of gids allowed in the supplemental group access
526
- # list.
969
+ # Returns the maximum number of group IDs allowed in the supplemental group
970
+ # access list:
527
971
  #
528
- # Process.maxgroups #=> 32
972
+ # Process.maxgroups # => 32
529
973
  #
530
974
  def self.maxgroups: () -> Integer
531
975
 
532
976
  # <!--
533
977
  # rdoc-file=process.c
534
- # - Process.maxgroups= integer -> integer
978
+ # - Process.maxgroups = new_max -> new_max
535
979
  # -->
536
- # Sets the maximum number of gids allowed in the supplemental group access list.
980
+ # Sets the maximum number of group IDs allowed in the supplemental group access
981
+ # list.
537
982
  #
538
983
  def self.maxgroups=: (Integer arg0) -> Integer
539
984
 
540
985
  # <!--
541
986
  # rdoc-file=process.c
542
- # - Process.pid -> integer
987
+ # - Process.pid -> integer
543
988
  # -->
544
- # Returns the process id of this process. Not available on all platforms.
989
+ # Returns the process ID of the current process:
545
990
  #
546
- # Process.pid #=> 27415
991
+ # Process.pid # => 15668
547
992
  #
548
993
  def self.pid: () -> Integer
549
994
 
550
995
  # <!--
551
996
  # rdoc-file=process.c
552
- # - Process.ppid -> integer
997
+ # - Process.ppid -> integer
553
998
  # -->
554
- # Returns the process id of the parent of this process. Returns untrustworthy
555
- # value on Win32/64. Not available on all platforms.
999
+ # Returns the process ID of the parent of the current process:
556
1000
  #
557
- # puts "I am #{Process.pid}"
558
- # Process.fork { puts "Dad is #{Process.ppid}" }
1001
+ # puts "Pid is #{Process.pid}."
1002
+ # fork { puts "Parent pid is #{Process.ppid}." }
559
1003
  #
560
- # *produces:*
1004
+ # Output:
561
1005
  #
562
- # I am 27417
563
- # Dad is 27417
1006
+ # Pid is 271290.
1007
+ # Parent pid is 271290.
1008
+ #
1009
+ # May not return a trustworthy value on certain platforms.
564
1010
  #
565
1011
  def self.ppid: () -> Integer
566
1012
 
567
1013
  # <!--
568
1014
  # rdoc-file=process.c
569
- # - Process.setpgid(pid, integer) -> 0
1015
+ # - Process.setpgid(pid, pgid) -> 0
570
1016
  # -->
571
- # Sets the process group ID of *pid* (0 indicates this process) to *integer*.
1017
+ # Sets the process group ID for the process given by process ID `pid` to `pgid`.
1018
+ #
572
1019
  # Not available on all platforms.
573
1020
  #
574
1021
  def self.setpgid: (Integer pid, Integer arg0) -> Integer
575
1022
 
576
1023
  # <!--
577
1024
  # rdoc-file=process.c
578
- # - Process.setpriority(kind, integer, priority) -> 0
1025
+ # - Process.setpriority(kind, integer, priority) -> 0
579
1026
  # -->
580
1027
  # See Process.getpriority.
581
1028
  #
582
- # Process.setpriority(Process::PRIO_USER, 0, 19) #=> 0
583
- # Process.setpriority(Process::PRIO_PROCESS, 0, 19) #=> 0
584
- # Process.getpriority(Process::PRIO_USER, 0) #=> 19
585
- # Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19
1029
+ # Examples:
1030
+ #
1031
+ # Process.setpriority(Process::PRIO_USER, 0, 19) # => 0
1032
+ # Process.setpriority(Process::PRIO_PROCESS, 0, 19) # => 0
1033
+ # Process.getpriority(Process::PRIO_USER, 0) # => 19
1034
+ # Process.getpriority(Process::PRIO_PROCESS, 0) # => 19
1035
+ #
1036
+ # Not available on all platforms.
586
1037
  #
587
1038
  def self.setpriority: (Integer kind, Integer arg0, Integer priority) -> Integer
588
1039
 
@@ -606,256 +1057,449 @@ module Process
606
1057
 
607
1058
  # <!--
608
1059
  # rdoc-file=process.c
609
- # - Process.setrlimit(resource, cur_limit, max_limit) -> nil
610
- # - Process.setrlimit(resource, cur_limit) -> nil
611
- # -->
612
- # Sets the resource limit of the process. *cur_limit* means current (soft) limit
613
- # and *max_limit* means maximum (hard) limit.
614
- #
615
- # If *max_limit* is not given, *cur_limit* is used.
616
- #
617
- # *resource* indicates the kind of resource to limit. It should be a symbol such
618
- # as `:CORE`, a string such as `"CORE"` or a constant such as
619
- # Process::RLIMIT_CORE. The available resources are OS dependent. Ruby may
620
- # support following resources.
621
- #
622
- # AS
623
- # : total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD but
624
- # 4.4BSD-Lite)
625
- # CORE
626
- # : core size (bytes) (SUSv3)
627
- # CPU
628
- # : CPU time (seconds) (SUSv3)
629
- # DATA
630
- # : data segment (bytes) (SUSv3)
631
- # FSIZE
632
- # : file size (bytes) (SUSv3)
633
- # MEMLOCK
634
- # : total size for mlock(2) (bytes) (4.4BSD, GNU/Linux)
635
- # MSGQUEUE
636
- # : allocation for POSIX message queues (bytes) (GNU/Linux)
637
- # NICE
638
- # : ceiling on process's nice(2) value (number) (GNU/Linux)
639
- # NOFILE
640
- # : file descriptors (number) (SUSv3)
641
- # NPROC
642
- # : number of processes for the user (number) (4.4BSD, GNU/Linux)
643
- # RSS
644
- # : resident memory size (bytes) (4.2BSD, GNU/Linux)
645
- # RTPRIO
646
- # : ceiling on the process's real-time priority (number) (GNU/Linux)
647
- # RTTIME
648
- # : CPU time for real-time process (us) (GNU/Linux)
649
- # SBSIZE
650
- # : all socket buffers (bytes) (NetBSD, FreeBSD)
651
- # SIGPENDING
652
- # : number of queued signals allowed (signals) (GNU/Linux)
653
- # STACK
654
- # : stack size (bytes) (SUSv3)
655
- #
656
- #
657
- # *cur_limit* and *max_limit* may be `:INFINITY`, `"INFINITY"` or
658
- # Process::RLIM_INFINITY, which means that the resource is not limited. They may
659
- # be Process::RLIM_SAVED_MAX, Process::RLIM_SAVED_CUR and corresponding symbols
660
- # and strings too. See system setrlimit(2) manual for details.
661
- #
662
- # The following example raises the soft limit of core size to the hard limit to
663
- # try to make core dump possible.
1060
+ # - Process.setrlimit(resource, cur_limit, max_limit = cur_limit) -> nil
1061
+ # -->
1062
+ # Sets limits for the current process for the given `resource` to `cur_limit`
1063
+ # (soft limit) and `max_limit` (hard limit); returns `nil`.
1064
+ #
1065
+ # Argument `resource` specifies the resource whose limits are to be set; the
1066
+ # argument may be given as a symbol, as a string, or as a constant beginning
1067
+ # with `Process::RLIMIT_` (e.g., `:CORE`, `'CORE'`, or `Process::RLIMIT_CORE`.
1068
+ #
1069
+ # The resources available and supported are system-dependent, and may include
1070
+ # (here expressed as symbols):
1071
+ #
1072
+ # * `:AS`: Total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD
1073
+ # except 4.4BSD-Lite).
1074
+ # * `:CORE`: Core size (bytes) (SUSv3).
1075
+ # * `:CPU`: CPU time (seconds) (SUSv3).
1076
+ # * `:DATA`: Data segment (bytes) (SUSv3).
1077
+ # * `:FSIZE`: File size (bytes) (SUSv3).
1078
+ # * `:MEMLOCK`: Total size for mlock(2) (bytes) (4.4BSD, GNU/Linux).
1079
+ # * `:MSGQUEUE`: Allocation for POSIX message queues (bytes) (GNU/Linux).
1080
+ # * `:NICE`: Ceiling on process's nice(2) value (number) (GNU/Linux).
1081
+ # * `:NOFILE`: File descriptors (number) (SUSv3).
1082
+ # * `:NPROC`: Number of processes for the user (number) (4.4BSD, GNU/Linux).
1083
+ # * `:NPTS`: Number of pseudo terminals (number) (FreeBSD).
1084
+ # * `:RSS`: Resident memory size (bytes) (4.2BSD, GNU/Linux).
1085
+ # * `:RTPRIO`: Ceiling on the process's real-time priority (number)
1086
+ # (GNU/Linux).
1087
+ # * `:RTTIME`: CPU time for real-time process (us) (GNU/Linux).
1088
+ # * `:SBSIZE`: All socket buffers (bytes) (NetBSD, FreeBSD).
1089
+ # * `:SIGPENDING`: Number of queued signals allowed (signals) (GNU/Linux).
1090
+ # * `:STACK`: Stack size (bytes) (SUSv3).
1091
+ #
1092
+ # Arguments `cur_limit` and `max_limit` may be:
1093
+ #
1094
+ # * Integers (`max_limit` should not be smaller than `cur_limit`).
1095
+ # * Symbol `:SAVED_MAX`, string `'SAVED_MAX'`, or constant
1096
+ # `Process::RLIM_SAVED_MAX`: saved maximum limit.
1097
+ # * Symbol `:SAVED_CUR`, string `'SAVED_CUR'`, or constant
1098
+ # `Process::RLIM_SAVED_CUR`: saved current limit.
1099
+ # * Symbol `:INFINITY`, string `'INFINITY'`, or constant
1100
+ # `Process::RLIM_INFINITY`: no limit on resource.
1101
+ #
1102
+ # This example raises the soft limit of core size to the hard limit to try to
1103
+ # make core dump possible:
664
1104
  #
665
1105
  # Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1])
666
1106
  #
667
- def self.setrlimit: (Symbol | String | Integer resource, Integer cur_limit, ?Integer max_limit) -> nil
1107
+ # Not available on all platforms.
1108
+ #
1109
+ def self.setrlimit: (interned | Integer resource, Integer cur_limit, ?Integer max_limit) -> nil
668
1110
 
669
1111
  # <!--
670
1112
  # rdoc-file=process.c
671
- # - Process.setsid -> integer
1113
+ # - Process.setsid -> integer
672
1114
  # -->
673
- # Establishes this process as a new session and process group leader, with no
674
- # controlling tty. Returns the session id. Not available on all platforms.
1115
+ # Establishes the current process as a new session and process group leader,
1116
+ # with no controlling tty; returns the session ID:
675
1117
  #
676
- # Process.setsid #=> 27422
1118
+ # Process.setsid # => 27422
1119
+ #
1120
+ # Not available on all platforms.
677
1121
  #
678
1122
  def self.setsid: () -> Integer
679
1123
 
680
1124
  # <!--
681
1125
  # rdoc-file=process.c
682
- # - Process.times -> aProcessTms
1126
+ # - Process.times -> process_tms
683
1127
  # -->
684
- # Returns a `Tms` structure (see Process::Tms) that contains user and system CPU
685
- # times for this process, and also for children processes.
1128
+ # Returns a Process::Tms structure that contains user and system CPU times for
1129
+ # the current process, and for its children processes:
686
1130
  #
687
- # t = Process.times
688
- # [ t.utime, t.stime, t.cutime, t.cstime ] #=> [0.0, 0.02, 0.00, 0.00]
1131
+ # Process.times
1132
+ # # => #<struct Process::Tms utime=55.122118, stime=35.533068, cutime=0.0, cstime=0.002846>
1133
+ #
1134
+ # The precision is platform-defined.
689
1135
  #
690
1136
  def self.times: () -> Process::Tms
691
1137
 
692
1138
  # <!--
693
1139
  # rdoc-file=process.c
694
- # - Process.uid -> integer
695
- # - Process::UID.rid -> integer
696
- # - Process::Sys.getuid -> integer
1140
+ # - Process.uid -> integer
1141
+ # - Process::UID.rid -> integer
1142
+ # - Process::Sys.getuid -> integer
697
1143
  # -->
698
- # Returns the (real) user ID of this process.
1144
+ # Returns the (real) user ID of the current process.
699
1145
  #
700
- # Process.uid #=> 501
1146
+ # Process.uid # => 1000
701
1147
  #
702
1148
  def self.uid: () -> Integer
703
1149
 
704
1150
  # <!--
705
1151
  # rdoc-file=process.c
706
- # - Process.uid= user -> numeric
1152
+ # - Process.uid = new_uid -> new_uid
707
1153
  # -->
708
- # Sets the (user) user ID for this process. Not available on all platforms.
1154
+ # Sets the (user) user ID for the current process to `new_uid`:
1155
+ #
1156
+ # Process.uid = 1000 # => 1000
1157
+ #
1158
+ # Not available on all platforms.
709
1159
  #
710
1160
  def self.uid=: (Integer user) -> Integer
711
1161
 
712
1162
  # <!--
713
1163
  # rdoc-file=process.c
714
- # - Process.wait() -> integer
715
- # - Process.wait(pid=-1, flags=0) -> integer
716
- # - Process.waitpid(pid=-1, flags=0) -> integer
717
- # -->
718
- # Waits for a child process to exit, returns its process id, and sets `$?` to a
719
- # Process::Status object containing information on that process. Which child it
720
- # waits on depends on the value of *pid*:
721
- #
722
- # > 0
723
- # : Waits for the child whose process ID equals *pid*.
724
- #
725
- # 0
726
- # : Waits for any child whose process group ID equals that of the calling
727
- # process.
728
- #
729
- # -1
730
- # : Waits for any child process (the default if no *pid* is given).
1164
+ # - Process.wait(pid = -1, flags = 0) -> integer
1165
+ # -->
1166
+ # Waits for a suitable child process to exit, returns its process ID, and sets
1167
+ # `$?` to a Process::Status object containing information on that process. Which
1168
+ # child it waits for depends on the value of the given `pid`:
1169
+ #
1170
+ # * Positive integer: Waits for the child process whose process ID is `pid`:
1171
+ #
1172
+ # pid0 = Process.spawn('ruby', '-e', 'exit 13') # => 230866
1173
+ # pid1 = Process.spawn('ruby', '-e', 'exit 14') # => 230891
1174
+ # Process.wait(pid0) # => 230866
1175
+ # $? # => #<Process::Status: pid 230866 exit 13>
1176
+ # Process.wait(pid1) # => 230891
1177
+ # $? # => #<Process::Status: pid 230891 exit 14>
1178
+ # Process.wait(pid0) # Raises Errno::ECHILD
1179
+ #
1180
+ # * `0`: Waits for any child process whose group ID is the same as that of the
1181
+ # current process:
1182
+ #
1183
+ # parent_pgpid = Process.getpgid(Process.pid)
1184
+ # puts "Parent process group ID is #{parent_pgpid}."
1185
+ # child0_pid = fork do
1186
+ # puts "Child 0 pid is #{Process.pid}"
1187
+ # child0_pgid = Process.getpgid(Process.pid)
1188
+ # puts "Child 0 process group ID is #{child0_pgid} (same as parent's)."
1189
+ # end
1190
+ # child1_pid = fork do
1191
+ # puts "Child 1 pid is #{Process.pid}"
1192
+ # Process.setpgid(0, Process.pid)
1193
+ # child1_pgid = Process.getpgid(Process.pid)
1194
+ # puts "Child 1 process group ID is #{child1_pgid} (different from parent's)."
1195
+ # end
1196
+ # retrieved_pid = Process.wait(0)
1197
+ # puts "Process.wait(0) returned pid #{retrieved_pid}, which is child 0 pid."
1198
+ # begin
1199
+ # Process.wait(0)
1200
+ # rescue Errno::ECHILD => x
1201
+ # puts "Raised #{x.class}, because child 1 process group ID differs from parent process group ID."
1202
+ # end
1203
+ #
1204
+ # Output:
1205
+ #
1206
+ # Parent process group ID is 225764.
1207
+ # Child 0 pid is 225788
1208
+ # Child 0 process group ID is 225764 (same as parent's).
1209
+ # Child 1 pid is 225789
1210
+ # Child 1 process group ID is 225789 (different from parent's).
1211
+ # Process.wait(0) returned pid 225788, which is child 0 pid.
1212
+ # Raised Errno::ECHILD, because child 1 process group ID differs from parent process group ID.
1213
+ #
1214
+ # * `-1` (default): Waits for any child process:
1215
+ #
1216
+ # parent_pgpid = Process.getpgid(Process.pid)
1217
+ # puts "Parent process group ID is #{parent_pgpid}."
1218
+ # child0_pid = fork do
1219
+ # puts "Child 0 pid is #{Process.pid}"
1220
+ # child0_pgid = Process.getpgid(Process.pid)
1221
+ # puts "Child 0 process group ID is #{child0_pgid} (same as parent's)."
1222
+ # end
1223
+ # child1_pid = fork do
1224
+ # puts "Child 1 pid is #{Process.pid}"
1225
+ # Process.setpgid(0, Process.pid)
1226
+ # child1_pgid = Process.getpgid(Process.pid)
1227
+ # puts "Child 1 process group ID is #{child1_pgid} (different from parent's)."
1228
+ # sleep 3 # To force child 1 to exit later than child 0 exit.
1229
+ # end
1230
+ # child_pids = [child0_pid, child1_pid]
1231
+ # retrieved_pid = Process.wait(-1)
1232
+ # puts child_pids.include?(retrieved_pid)
1233
+ # retrieved_pid = Process.wait(-1)
1234
+ # puts child_pids.include?(retrieved_pid)
1235
+ #
1236
+ # Output:
1237
+ #
1238
+ # Parent process group ID is 228736.
1239
+ # Child 0 pid is 228758
1240
+ # Child 0 process group ID is 228736 (same as parent's).
1241
+ # Child 1 pid is 228759
1242
+ # Child 1 process group ID is 228759 (different from parent's).
1243
+ # true
1244
+ # true
1245
+ #
1246
+ # * Less than `-1`: Waits for any child whose process group ID is `-pid`:
1247
+ #
1248
+ # parent_pgpid = Process.getpgid(Process.pid)
1249
+ # puts "Parent process group ID is #{parent_pgpid}."
1250
+ # child0_pid = fork do
1251
+ # puts "Child 0 pid is #{Process.pid}"
1252
+ # child0_pgid = Process.getpgid(Process.pid)
1253
+ # puts "Child 0 process group ID is #{child0_pgid} (same as parent's)."
1254
+ # end
1255
+ # child1_pid = fork do
1256
+ # puts "Child 1 pid is #{Process.pid}"
1257
+ # Process.setpgid(0, Process.pid)
1258
+ # child1_pgid = Process.getpgid(Process.pid)
1259
+ # puts "Child 1 process group ID is #{child1_pgid} (different from parent's)."
1260
+ # end
1261
+ # sleep 1
1262
+ # retrieved_pid = Process.wait(-child1_pid)
1263
+ # puts "Process.wait(-child1_pid) returned pid #{retrieved_pid}, which is child 1 pid."
1264
+ # begin
1265
+ # Process.wait(-child1_pid)
1266
+ # rescue Errno::ECHILD => x
1267
+ # puts "Raised #{x.class}, because there's no longer a child with process group id #{child1_pid}."
1268
+ # end
1269
+ #
1270
+ # Output:
1271
+ #
1272
+ # Parent process group ID is 230083.
1273
+ # Child 0 pid is 230108
1274
+ # Child 0 process group ID is 230083 (same as parent's).
1275
+ # Child 1 pid is 230109
1276
+ # Child 1 process group ID is 230109 (different from parent's).
1277
+ # Process.wait(-child1_pid) returned pid 230109, which is child 1 pid.
1278
+ # Raised Errno::ECHILD, because there's no longer a child with process group id 230109.
1279
+ #
1280
+ # Argument `flags` should be given as one of the following constants, or as the
1281
+ # logical OR of both:
1282
+ #
1283
+ # * Process::WNOHANG: Does not block if no child process is available.
1284
+ # * Process::WUNTRACED: May return a stopped child process, even if not yet
1285
+ # reported.
1286
+ #
1287
+ # Not all flags are available on all platforms.
1288
+ #
1289
+ # Raises Errno::ECHILD if there is no suitable child process.
731
1290
  #
732
- # < -1
733
- # : Waits for any child whose process group ID equals the absolute value of
734
- # *pid*.
735
- #
736
- #
737
- # The *flags* argument may be a logical or of the flag values Process::WNOHANG
738
- # (do not block if no child available) or Process::WUNTRACED (return stopped
739
- # children that haven't been reported). Not all flags are available on all
740
- # platforms, but a flag value of zero will work on all platforms.
741
- #
742
- # Calling this method raises a SystemCallError if there are no child processes.
743
1291
  # Not available on all platforms.
744
1292
  #
745
- # include Process
746
- # fork { exit 99 } #=> 27429
747
- # wait #=> 27429
748
- # $?.exitstatus #=> 99
749
- #
750
- # pid = fork { sleep 3 } #=> 27440
751
- # Time.now #=> 2008-03-08 19:56:16 +0900
752
- # waitpid(pid, Process::WNOHANG) #=> nil
753
- # Time.now #=> 2008-03-08 19:56:16 +0900
754
- # waitpid(pid, 0) #=> 27440
755
- # Time.now #=> 2008-03-08 19:56:19 +0900
1293
+ # Process.waitpid is an alias for Process.wait.
756
1294
  #
757
1295
  def self.wait: (?Integer pid, ?Integer flags) -> Integer
758
1296
 
759
1297
  # <!--
760
1298
  # rdoc-file=process.c
761
- # - Process.wait2(pid=-1, flags=0) -> [pid, status]
762
- # - Process.waitpid2(pid=-1, flags=0) -> [pid, status]
1299
+ # - Process.wait2(pid = -1, flags = 0) -> [pid, status]
763
1300
  # -->
764
- # Waits for a child process to exit (see Process::waitpid for exact semantics)
765
- # and returns an array containing the process id and the exit status (a
766
- # Process::Status object) of that child. Raises a SystemCallError if there are
767
- # no child processes.
1301
+ # Like Process.waitpid, but returns an array containing the child process `pid`
1302
+ # and Process::Status `status`:
768
1303
  #
769
- # Process.fork { exit 99 } #=> 27437
770
- # pid, status = Process.wait2
771
- # pid #=> 27437
772
- # status.exitstatus #=> 99
1304
+ # pid = Process.spawn('ruby', '-e', 'exit 13') # => 309581
1305
+ # Process.wait2(pid)
1306
+ # # => [309581, #<Process::Status: pid 309581 exit 13>]
1307
+ #
1308
+ # Process.waitpid2 is an alias for Process.wait2.
773
1309
  #
774
1310
  def self.wait2: (?Integer pid, ?Integer flags) -> [ Integer, Process::Status ]
775
1311
 
776
1312
  # <!--
777
1313
  # rdoc-file=process.c
778
- # - Process.waitall -> [ [pid1,status1], ...]
1314
+ # - Process.waitall -> array
779
1315
  # -->
780
- # Waits for all children, returning an array of *pid*/*status* pairs (where
781
- # *status* is a Process::Status object).
782
- #
783
- # fork { sleep 0.2; exit 2 } #=> 27432
784
- # fork { sleep 0.1; exit 1 } #=> 27433
785
- # fork { exit 0 } #=> 27434
786
- # p Process.waitall
1316
+ # Waits for all children, returns an array of 2-element arrays; each subarray
1317
+ # contains the integer pid and Process::Status status for one of the reaped
1318
+ # child processes:
787
1319
  #
788
- # *produces*:
789
- #
790
- # [[30982, #<Process::Status: pid 30982 exit 0>],
791
- # [30979, #<Process::Status: pid 30979 exit 1>],
792
- # [30976, #<Process::Status: pid 30976 exit 2>]]
1320
+ # pid0 = Process.spawn('ruby', '-e', 'exit 13') # => 325470
1321
+ # pid1 = Process.spawn('ruby', '-e', 'exit 14') # => 325495
1322
+ # Process.waitall
1323
+ # # => [[325470, #<Process::Status: pid 325470 exit 13>], [325495, #<Process::Status: pid 325495 exit 14>]]
793
1324
  #
794
1325
  def self.waitall: () -> ::Array[[ Integer, Process::Status ]]
795
1326
 
796
1327
  # <!--
797
1328
  # rdoc-file=process.c
798
- # - Process.wait() -> integer
799
- # - Process.wait(pid=-1, flags=0) -> integer
800
- # - Process.waitpid(pid=-1, flags=0) -> integer
801
- # -->
802
- # Waits for a child process to exit, returns its process id, and sets `$?` to a
803
- # Process::Status object containing information on that process. Which child it
804
- # waits on depends on the value of *pid*:
805
- #
806
- # > 0
807
- # : Waits for the child whose process ID equals *pid*.
808
- #
809
- # 0
810
- # : Waits for any child whose process group ID equals that of the calling
811
- # process.
812
- #
813
- # -1
814
- # : Waits for any child process (the default if no *pid* is given).
815
- #
816
- # < -1
817
- # : Waits for any child whose process group ID equals the absolute value of
818
- # *pid*.
1329
+ # - Process.wait(pid = -1, flags = 0) -> integer
1330
+ # -->
1331
+ # Waits for a suitable child process to exit, returns its process ID, and sets
1332
+ # `$?` to a Process::Status object containing information on that process. Which
1333
+ # child it waits for depends on the value of the given `pid`:
1334
+ #
1335
+ # * Positive integer: Waits for the child process whose process ID is `pid`:
1336
+ #
1337
+ # pid0 = Process.spawn('ruby', '-e', 'exit 13') # => 230866
1338
+ # pid1 = Process.spawn('ruby', '-e', 'exit 14') # => 230891
1339
+ # Process.wait(pid0) # => 230866
1340
+ # $? # => #<Process::Status: pid 230866 exit 13>
1341
+ # Process.wait(pid1) # => 230891
1342
+ # $? # => #<Process::Status: pid 230891 exit 14>
1343
+ # Process.wait(pid0) # Raises Errno::ECHILD
1344
+ #
1345
+ # * `0`: Waits for any child process whose group ID is the same as that of the
1346
+ # current process:
1347
+ #
1348
+ # parent_pgpid = Process.getpgid(Process.pid)
1349
+ # puts "Parent process group ID is #{parent_pgpid}."
1350
+ # child0_pid = fork do
1351
+ # puts "Child 0 pid is #{Process.pid}"
1352
+ # child0_pgid = Process.getpgid(Process.pid)
1353
+ # puts "Child 0 process group ID is #{child0_pgid} (same as parent's)."
1354
+ # end
1355
+ # child1_pid = fork do
1356
+ # puts "Child 1 pid is #{Process.pid}"
1357
+ # Process.setpgid(0, Process.pid)
1358
+ # child1_pgid = Process.getpgid(Process.pid)
1359
+ # puts "Child 1 process group ID is #{child1_pgid} (different from parent's)."
1360
+ # end
1361
+ # retrieved_pid = Process.wait(0)
1362
+ # puts "Process.wait(0) returned pid #{retrieved_pid}, which is child 0 pid."
1363
+ # begin
1364
+ # Process.wait(0)
1365
+ # rescue Errno::ECHILD => x
1366
+ # puts "Raised #{x.class}, because child 1 process group ID differs from parent process group ID."
1367
+ # end
1368
+ #
1369
+ # Output:
1370
+ #
1371
+ # Parent process group ID is 225764.
1372
+ # Child 0 pid is 225788
1373
+ # Child 0 process group ID is 225764 (same as parent's).
1374
+ # Child 1 pid is 225789
1375
+ # Child 1 process group ID is 225789 (different from parent's).
1376
+ # Process.wait(0) returned pid 225788, which is child 0 pid.
1377
+ # Raised Errno::ECHILD, because child 1 process group ID differs from parent process group ID.
1378
+ #
1379
+ # * `-1` (default): Waits for any child process:
1380
+ #
1381
+ # parent_pgpid = Process.getpgid(Process.pid)
1382
+ # puts "Parent process group ID is #{parent_pgpid}."
1383
+ # child0_pid = fork do
1384
+ # puts "Child 0 pid is #{Process.pid}"
1385
+ # child0_pgid = Process.getpgid(Process.pid)
1386
+ # puts "Child 0 process group ID is #{child0_pgid} (same as parent's)."
1387
+ # end
1388
+ # child1_pid = fork do
1389
+ # puts "Child 1 pid is #{Process.pid}"
1390
+ # Process.setpgid(0, Process.pid)
1391
+ # child1_pgid = Process.getpgid(Process.pid)
1392
+ # puts "Child 1 process group ID is #{child1_pgid} (different from parent's)."
1393
+ # sleep 3 # To force child 1 to exit later than child 0 exit.
1394
+ # end
1395
+ # child_pids = [child0_pid, child1_pid]
1396
+ # retrieved_pid = Process.wait(-1)
1397
+ # puts child_pids.include?(retrieved_pid)
1398
+ # retrieved_pid = Process.wait(-1)
1399
+ # puts child_pids.include?(retrieved_pid)
1400
+ #
1401
+ # Output:
1402
+ #
1403
+ # Parent process group ID is 228736.
1404
+ # Child 0 pid is 228758
1405
+ # Child 0 process group ID is 228736 (same as parent's).
1406
+ # Child 1 pid is 228759
1407
+ # Child 1 process group ID is 228759 (different from parent's).
1408
+ # true
1409
+ # true
1410
+ #
1411
+ # * Less than `-1`: Waits for any child whose process group ID is `-pid`:
1412
+ #
1413
+ # parent_pgpid = Process.getpgid(Process.pid)
1414
+ # puts "Parent process group ID is #{parent_pgpid}."
1415
+ # child0_pid = fork do
1416
+ # puts "Child 0 pid is #{Process.pid}"
1417
+ # child0_pgid = Process.getpgid(Process.pid)
1418
+ # puts "Child 0 process group ID is #{child0_pgid} (same as parent's)."
1419
+ # end
1420
+ # child1_pid = fork do
1421
+ # puts "Child 1 pid is #{Process.pid}"
1422
+ # Process.setpgid(0, Process.pid)
1423
+ # child1_pgid = Process.getpgid(Process.pid)
1424
+ # puts "Child 1 process group ID is #{child1_pgid} (different from parent's)."
1425
+ # end
1426
+ # sleep 1
1427
+ # retrieved_pid = Process.wait(-child1_pid)
1428
+ # puts "Process.wait(-child1_pid) returned pid #{retrieved_pid}, which is child 1 pid."
1429
+ # begin
1430
+ # Process.wait(-child1_pid)
1431
+ # rescue Errno::ECHILD => x
1432
+ # puts "Raised #{x.class}, because there's no longer a child with process group id #{child1_pid}."
1433
+ # end
1434
+ #
1435
+ # Output:
1436
+ #
1437
+ # Parent process group ID is 230083.
1438
+ # Child 0 pid is 230108
1439
+ # Child 0 process group ID is 230083 (same as parent's).
1440
+ # Child 1 pid is 230109
1441
+ # Child 1 process group ID is 230109 (different from parent's).
1442
+ # Process.wait(-child1_pid) returned pid 230109, which is child 1 pid.
1443
+ # Raised Errno::ECHILD, because there's no longer a child with process group id 230109.
1444
+ #
1445
+ # Argument `flags` should be given as one of the following constants, or as the
1446
+ # logical OR of both:
1447
+ #
1448
+ # * Process::WNOHANG: Does not block if no child process is available.
1449
+ # * Process::WUNTRACED: May return a stopped child process, even if not yet
1450
+ # reported.
1451
+ #
1452
+ # Not all flags are available on all platforms.
1453
+ #
1454
+ # Raises Errno::ECHILD if there is no suitable child process.
819
1455
  #
820
- #
821
- # The *flags* argument may be a logical or of the flag values Process::WNOHANG
822
- # (do not block if no child available) or Process::WUNTRACED (return stopped
823
- # children that haven't been reported). Not all flags are available on all
824
- # platforms, but a flag value of zero will work on all platforms.
825
- #
826
- # Calling this method raises a SystemCallError if there are no child processes.
827
1456
  # Not available on all platforms.
828
1457
  #
829
- # include Process
830
- # fork { exit 99 } #=> 27429
831
- # wait #=> 27429
832
- # $?.exitstatus #=> 99
833
- #
834
- # pid = fork { sleep 3 } #=> 27440
835
- # Time.now #=> 2008-03-08 19:56:16 +0900
836
- # waitpid(pid, Process::WNOHANG) #=> nil
837
- # Time.now #=> 2008-03-08 19:56:16 +0900
838
- # waitpid(pid, 0) #=> 27440
839
- # Time.now #=> 2008-03-08 19:56:19 +0900
1458
+ # Process.waitpid is an alias for Process.wait.
840
1459
  #
841
1460
  def self.waitpid: (?Integer pid, ?Integer flags) -> Integer
842
1461
 
843
1462
  # <!--
844
1463
  # rdoc-file=process.c
845
- # - Process.wait2(pid=-1, flags=0) -> [pid, status]
846
- # - Process.waitpid2(pid=-1, flags=0) -> [pid, status]
1464
+ # - Process.wait2(pid = -1, flags = 0) -> [pid, status]
847
1465
  # -->
848
- # Waits for a child process to exit (see Process::waitpid for exact semantics)
849
- # and returns an array containing the process id and the exit status (a
850
- # Process::Status object) of that child. Raises a SystemCallError if there are
851
- # no child processes.
1466
+ # Like Process.waitpid, but returns an array containing the child process `pid`
1467
+ # and Process::Status `status`:
1468
+ #
1469
+ # pid = Process.spawn('ruby', '-e', 'exit 13') # => 309581
1470
+ # Process.wait2(pid)
1471
+ # # => [309581, #<Process::Status: pid 309581 exit 13>]
852
1472
  #
853
- # Process.fork { exit 99 } #=> 27437
854
- # pid, status = Process.wait2
855
- # pid #=> 27437
856
- # status.exitstatus #=> 99
1473
+ # Process.waitpid2 is an alias for Process.wait2.
857
1474
  #
858
1475
  def self.waitpid2: (?Integer pid, ?Integer flags) -> [ Integer, Process::Status ]
1476
+
1477
+ # <!--
1478
+ # rdoc-file=process.c
1479
+ # - Process.warmup -> true
1480
+ # -->
1481
+ # Notify the Ruby virtual machine that the boot sequence is finished, and that
1482
+ # now is a good time to optimize the application. This is useful for long
1483
+ # running applications.
1484
+ #
1485
+ # This method is expected to be called at the end of the application boot. If
1486
+ # the application is deployed using a pre-forking model, `Process.warmup` should
1487
+ # be called in the original process before the first fork.
1488
+ #
1489
+ # The actual optimizations performed are entirely implementation specific and
1490
+ # may change in the future without notice.
1491
+ #
1492
+ # On CRuby, `Process.warmup`:
1493
+ #
1494
+ # * Performs a major GC.
1495
+ # * Compacts the heap.
1496
+ # * Promotes all surviving objects to the old generation.
1497
+ # * Precomputes the coderange of all strings.
1498
+ # * Frees all empty heap pages and increments the allocatable pages counter by
1499
+ # the number of pages freed.
1500
+ # * Invoke `malloc_trim` if available to free empty malloc pages.
1501
+ #
1502
+ def self.warmup: () -> bool
859
1503
  end
860
1504
 
861
1505
  # <!-- rdoc-file=process.c -->
@@ -996,6 +1640,14 @@ Process::RLIMIT_NOFILE: Integer
996
1640
  #
997
1641
  Process::RLIMIT_NPROC: Integer
998
1642
 
1643
+ # <!-- rdoc-file=process.c -->
1644
+ # The maximum number of pseudo-terminals that can be created for the real user
1645
+ # ID of the calling process.
1646
+ #
1647
+ # see the system getrlimit(2) manual for details.
1648
+ #
1649
+ Process::RLIMIT_NPTS: Integer
1650
+
999
1651
  # <!-- rdoc-file=process.c -->
1000
1652
  # Specifies the limit (in pages) of the process's resident set.
1001
1653
  #
@@ -1080,14 +1732,15 @@ module Process::GID
1080
1732
 
1081
1733
  # <!--
1082
1734
  # rdoc-file=process.c
1083
- # - Process.egid -> integer
1084
- # - Process::GID.eid -> integer
1085
- # - Process::Sys.geteid -> integer
1735
+ # - Process.egid -> integer
1736
+ # - Process::GID.eid -> integer
1737
+ # - Process::Sys.geteid -> integer
1086
1738
  # -->
1087
- # Returns the effective group ID for this process. Not available on all
1088
- # platforms.
1739
+ # Returns the effective group ID for the current process:
1089
1740
  #
1090
- # Process.egid #=> 500
1741
+ # Process.egid # => 500
1742
+ #
1743
+ # Not available on all platforms.
1091
1744
  #
1092
1745
  def self.eid: () -> Integer
1093
1746
 
@@ -1142,13 +1795,13 @@ module Process::GID
1142
1795
 
1143
1796
  # <!--
1144
1797
  # rdoc-file=process.c
1145
- # - Process.gid -> integer
1146
- # - Process::GID.rid -> integer
1147
- # - Process::Sys.getgid -> integer
1798
+ # - Process.gid -> integer
1799
+ # - Process::GID.rid -> integer
1800
+ # - Process::Sys.getgid -> integer
1148
1801
  # -->
1149
- # Returns the (real) group ID for this process.
1802
+ # Returns the (real) group ID for the current process:
1150
1803
  #
1151
- # Process.gid #=> 500
1804
+ # Process.gid # => 1000
1152
1805
  #
1153
1806
  def self.rid: () -> Integer
1154
1807
 
@@ -1177,188 +1830,192 @@ module Process::GID
1177
1830
  end
1178
1831
 
1179
1832
  # <!-- rdoc-file=process.c -->
1180
- # Process::Status encapsulates the information on the status of a running or
1181
- # terminated system process. The built-in variable `$?` is either `nil` or a
1182
- # Process::Status object.
1183
- #
1184
- # fork { exit 99 } #=> 26557
1185
- # Process.wait #=> 26557
1186
- # $?.class #=> Process::Status
1187
- # $?.to_i #=> 25344
1188
- # $? >> 8 #=> 99
1189
- # $?.stopped? #=> false
1190
- # $?.exited? #=> true
1191
- # $?.exitstatus #=> 99
1192
- #
1193
- # Posix systems record information on processes using a 16-bit integer. The
1194
- # lower bits record the process status (stopped, exited, signaled) and the upper
1195
- # bits possibly contain additional information (for example the program's return
1196
- # code in the case of exited processes). Pre Ruby 1.8, these bits were exposed
1197
- # directly to the Ruby program. Ruby now encapsulates these in a Process::Status
1198
- # object. To maximize compatibility, however, these objects retain a
1199
- # bit-oriented interface. In the descriptions that follow, when we talk about
1200
- # the integer value of *stat*, we're referring to this 16 bit value.
1833
+ # A Process::Status contains information about a system process.
1834
+ #
1835
+ # Thread-local variable `$?` is initially `nil`. Some methods assign to it a
1836
+ # Process::Status object that represents a system process (either running or
1837
+ # terminated):
1838
+ #
1839
+ # `ruby -e "exit 99"`
1840
+ # stat = $? # => #<Process::Status: pid 1262862 exit 99>
1841
+ # stat.class # => Process::Status
1842
+ # stat.to_i # => 25344
1843
+ # stat.stopped? # => false
1844
+ # stat.exited? # => true
1845
+ # stat.exitstatus # => 99
1201
1846
  #
1202
1847
  class Process::Status < Object
1203
1848
  # <!--
1204
1849
  # rdoc-file=process.c
1205
- # - stat & num -> integer
1850
+ # - stat & mask -> integer
1206
1851
  # -->
1207
- # Logical AND of the bits in *stat* with *num*.
1852
+ # This method is deprecated as #to_i value is system-specific; use predicate
1853
+ # methods like #exited? or #stopped?, or getters like #exitstatus or #stopsig.
1208
1854
  #
1209
- # fork { exit 0x37 }
1210
- # Process.wait
1211
- # sprintf('%04x', $?.to_i) #=> "3700"
1212
- # sprintf('%04x', $? & 0x1e00) #=> "1600"
1855
+ # Returns the logical AND of the value of #to_i with `mask`:
1856
+ #
1857
+ # `cat /nop`
1858
+ # stat = $? # => #<Process::Status: pid 1155508 exit 1>
1859
+ # sprintf('%x', stat.to_i) # => "100"
1860
+ # stat & 0x00 # => 0
1861
+ #
1862
+ # ArgumentError is raised if `mask` is negative.
1213
1863
  #
1214
1864
  def &: (Integer num) -> Integer
1215
1865
 
1216
1866
  # <!--
1217
1867
  # rdoc-file=process.c
1218
- # - stat == other -> true or false
1868
+ # - stat == other -> true or false
1219
1869
  # -->
1220
- # Returns `true` if the integer value of *stat* equals *other*.
1870
+ # Returns whether the value of #to_i == `other`:
1871
+ #
1872
+ # `cat /nop`
1873
+ # stat = $? # => #<Process::Status: pid 1170366 exit 1>
1874
+ # sprintf('%x', stat.to_i) # => "100"
1875
+ # stat == 0x100 # => true
1221
1876
  #
1222
1877
  def ==: (untyped other) -> bool
1223
1878
 
1224
1879
  # <!--
1225
1880
  # rdoc-file=process.c
1226
- # - stat >> num -> integer
1881
+ # - stat >> places -> integer
1227
1882
  # -->
1228
- # Shift the bits in *stat* right *num* places.
1883
+ # This method is deprecated as #to_i value is system-specific; use predicate
1884
+ # methods like #exited? or #stopped?, or getters like #exitstatus or #stopsig.
1229
1885
  #
1230
- # fork { exit 99 } #=> 26563
1231
- # Process.wait #=> 26563
1232
- # $?.to_i #=> 25344
1233
- # $? >> 8 #=> 99
1886
+ # Returns the value of #to_i, shifted `places` to the right:
1887
+ #
1888
+ # `cat /nop`
1889
+ # stat = $? # => #<Process::Status: pid 1155508 exit 1>
1890
+ # stat.to_i # => 256
1891
+ # stat >> 1 # => 128
1892
+ # stat >> 2 # => 64
1893
+ #
1894
+ # ArgumentError is raised if `places` is negative.
1234
1895
  #
1235
1896
  def >>: (Integer num) -> Integer
1236
1897
 
1237
1898
  # <!--
1238
1899
  # rdoc-file=process.c
1239
- # - stat.coredump? -> true or false
1900
+ # - coredump? -> true or false
1240
1901
  # -->
1241
- # Returns `true` if *stat* generated a coredump when it terminated. Not
1242
- # available on all platforms.
1902
+ # Returns `true` if the process generated a coredump when it terminated, `false`
1903
+ # if not.
1904
+ #
1905
+ # Not available on all platforms.
1243
1906
  #
1244
1907
  def coredump?: () -> bool
1245
1908
 
1246
1909
  # <!--
1247
1910
  # rdoc-file=process.c
1248
- # - stat.exited? -> true or false
1911
+ # - exited? -> true or false
1249
1912
  # -->
1250
- # Returns `true` if *stat* exited normally (for example using an `exit()` call
1251
- # or finishing the program).
1913
+ # Returns `true` if the process exited normally (for example using an `exit()`
1914
+ # call or finishing the program), `false` if not.
1252
1915
  #
1253
1916
  def exited?: () -> bool
1254
1917
 
1255
1918
  # <!--
1256
1919
  # rdoc-file=process.c
1257
- # - stat.exitstatus -> integer or nil
1920
+ # - exitstatus -> integer or nil
1258
1921
  # -->
1259
- # Returns the least significant eight bits of the return code of *stat*. Only
1260
- # available if #exited? is `true`.
1261
- #
1262
- # fork { } #=> 26572
1263
- # Process.wait #=> 26572
1264
- # $?.exited? #=> true
1265
- # $?.exitstatus #=> 0
1922
+ # Returns the least significant eight bits of the return code of the process if
1923
+ # it has exited; `nil` otherwise:
1266
1924
  #
1267
- # fork { exit 99 } #=> 26573
1268
- # Process.wait #=> 26573
1269
- # $?.exited? #=> true
1270
- # $?.exitstatus #=> 99
1925
+ # `exit 99`
1926
+ # $?.exitstatus # => 99
1271
1927
  #
1272
1928
  def exitstatus: () -> Integer?
1273
1929
 
1274
1930
  # <!--
1275
1931
  # rdoc-file=process.c
1276
- # - stat.inspect -> string
1932
+ # - inspect -> string
1277
1933
  # -->
1278
- # Override the inspection method.
1934
+ # Returns a string representation of `self`:
1279
1935
  #
1280
1936
  # system("false")
1281
- # p $?.inspect #=> "#<Process::Status: pid 12861 exit 1>"
1937
+ # $?.inspect # => "#<Process::Status: pid 1303494 exit 1>"
1282
1938
  #
1283
1939
  def inspect: () -> String
1284
1940
 
1285
1941
  # <!--
1286
1942
  # rdoc-file=process.c
1287
- # - stat.pid -> integer
1943
+ # - pid -> integer
1288
1944
  # -->
1289
- # Returns the process ID that this status object represents.
1945
+ # Returns the process ID of the process:
1290
1946
  #
1291
- # fork { exit } #=> 26569
1292
- # Process.wait #=> 26569
1293
- # $?.pid #=> 26569
1947
+ # system("false")
1948
+ # $?.pid # => 1247002
1294
1949
  #
1295
1950
  def pid: () -> Integer
1296
1951
 
1297
1952
  # <!--
1298
1953
  # rdoc-file=process.c
1299
- # - stat.signaled? -> true or false
1954
+ # - signaled? -> true or false
1300
1955
  # -->
1301
- # Returns `true` if *stat* terminated because of an uncaught signal.
1956
+ # Returns `true` if the process terminated because of an uncaught signal,
1957
+ # `false` otherwise.
1302
1958
  #
1303
1959
  def signaled?: () -> bool
1304
1960
 
1305
1961
  # <!--
1306
1962
  # rdoc-file=process.c
1307
- # - stat.stopped? -> true or false
1963
+ # - stopped? -> true or false
1308
1964
  # -->
1309
- # Returns `true` if this process is stopped. This is only returned if the
1310
- # corresponding #wait call had the Process::WUNTRACED flag set.
1965
+ # Returns `true` if this process is stopped, and if the corresponding #wait call
1966
+ # had the Process::WUNTRACED flag set, `false` otherwise.
1311
1967
  #
1312
1968
  def stopped?: () -> bool
1313
1969
 
1314
1970
  # <!--
1315
1971
  # rdoc-file=process.c
1316
- # - stat.stopsig -> integer or nil
1972
+ # - stopsig -> integer or nil
1317
1973
  # -->
1318
- # Returns the number of the signal that caused *stat* to stop (or `nil` if self
1319
- # is not stopped).
1974
+ # Returns the number of the signal that caused the process to stop, or `nil` if
1975
+ # the process is not stopped.
1320
1976
  #
1321
1977
  def stopsig: () -> Integer?
1322
1978
 
1323
1979
  # <!--
1324
1980
  # rdoc-file=process.c
1325
- # - stat.success? -> true, false or nil
1981
+ # - success? -> true, false, or nil
1326
1982
  # -->
1327
- # Returns `true` if *stat* is successful, `false` if not. Returns `nil` if
1328
- # #exited? is not `true`.
1983
+ # Returns:
1984
+ #
1985
+ # * `true` if the process has completed successfully and exited.
1986
+ # * `false` if the process has completed unsuccessfully and exited.
1987
+ # * `nil` if the process has not exited.
1329
1988
  #
1330
1989
  def success?: () -> bool
1331
1990
 
1332
1991
  # <!--
1333
1992
  # rdoc-file=process.c
1334
- # - stat.termsig -> integer or nil
1993
+ # - termsig -> integer or nil
1335
1994
  # -->
1336
- # Returns the number of the signal that caused *stat* to terminate (or `nil` if
1337
- # self was not terminated by an uncaught signal).
1995
+ # Returns the number of the signal that caused the process to terminate or `nil`
1996
+ # if the process was not terminated by an uncaught signal.
1338
1997
  #
1339
1998
  def termsig: () -> Integer?
1340
1999
 
1341
2000
  # <!--
1342
2001
  # rdoc-file=process.c
1343
- # - stat.to_i -> integer
2002
+ # - to_i -> integer
1344
2003
  # -->
1345
- # Returns the bits in *stat* as an Integer. Poking around in these bits is
1346
- # platform dependent.
2004
+ # Returns the system-dependent integer status of `self`:
1347
2005
  #
1348
- # fork { exit 0xab } #=> 26566
1349
- # Process.wait #=> 26566
1350
- # sprintf('%04x', $?.to_i) #=> "ab00"
2006
+ # `cat /nop`
2007
+ # $?.to_i # => 256
1351
2008
  #
1352
2009
  def to_i: () -> Integer
1353
2010
 
1354
2011
  # <!--
1355
2012
  # rdoc-file=process.c
1356
- # - stat.to_s -> string
2013
+ # - to_s -> string
1357
2014
  # -->
1358
- # Show pid and exit status as a string.
2015
+ # Returns a string representation of `self`:
1359
2016
  #
1360
- # system("false")
1361
- # p $?.to_s #=> "pid 12766 exit 1"
2017
+ # `cat /nop`
2018
+ # $?.to_s # => "pid 1262141 exit 1"
1362
2019
  #
1363
2020
  def to_s: () -> String
1364
2021
  end
@@ -1372,37 +2029,37 @@ end
1372
2029
  module Process::Sys
1373
2030
  # <!--
1374
2031
  # rdoc-file=process.c
1375
- # - Process.euid -> integer
1376
- # - Process::UID.eid -> integer
1377
- # - Process::Sys.geteuid -> integer
2032
+ # - Process.euid -> integer
2033
+ # - Process::UID.eid -> integer
2034
+ # - Process::Sys.geteuid -> integer
1378
2035
  # -->
1379
- # Returns the effective user ID for this process.
2036
+ # Returns the effective user ID for the current process.
1380
2037
  #
1381
- # Process.euid #=> 501
2038
+ # Process.euid # => 501
1382
2039
  #
1383
2040
  def self.geteuid: () -> Integer
1384
2041
 
1385
2042
  # <!--
1386
2043
  # rdoc-file=process.c
1387
- # - Process.gid -> integer
1388
- # - Process::GID.rid -> integer
1389
- # - Process::Sys.getgid -> integer
2044
+ # - Process.gid -> integer
2045
+ # - Process::GID.rid -> integer
2046
+ # - Process::Sys.getgid -> integer
1390
2047
  # -->
1391
- # Returns the (real) group ID for this process.
2048
+ # Returns the (real) group ID for the current process:
1392
2049
  #
1393
- # Process.gid #=> 500
2050
+ # Process.gid # => 1000
1394
2051
  #
1395
2052
  def self.getgid: () -> Integer
1396
2053
 
1397
2054
  # <!--
1398
2055
  # rdoc-file=process.c
1399
- # - Process.uid -> integer
1400
- # - Process::UID.rid -> integer
1401
- # - Process::Sys.getuid -> integer
2056
+ # - Process.uid -> integer
2057
+ # - Process::UID.rid -> integer
2058
+ # - Process::Sys.getuid -> integer
1402
2059
  # -->
1403
- # Returns the (real) user ID of this process.
2060
+ # Returns the (real) user ID of the current process.
1404
2061
  #
1405
- # Process.uid #=> 501
2062
+ # Process.uid # => 1000
1406
2063
  #
1407
2064
  def self.getuid: () -> Integer
1408
2065
 
@@ -1533,13 +2190,13 @@ module Process::UID
1533
2190
 
1534
2191
  # <!--
1535
2192
  # rdoc-file=process.c
1536
- # - Process.euid -> integer
1537
- # - Process::UID.eid -> integer
1538
- # - Process::Sys.geteuid -> integer
2193
+ # - Process.euid -> integer
2194
+ # - Process::UID.eid -> integer
2195
+ # - Process::Sys.geteuid -> integer
1539
2196
  # -->
1540
- # Returns the effective user ID for this process.
2197
+ # Returns the effective user ID for the current process.
1541
2198
  #
1542
- # Process.euid #=> 501
2199
+ # Process.euid # => 501
1543
2200
  #
1544
2201
  def self.eid: () -> Integer
1545
2202
 
@@ -1594,13 +2251,13 @@ module Process::UID
1594
2251
 
1595
2252
  # <!--
1596
2253
  # rdoc-file=process.c
1597
- # - Process.uid -> integer
1598
- # - Process::UID.rid -> integer
1599
- # - Process::Sys.getuid -> integer
2254
+ # - Process.uid -> integer
2255
+ # - Process::UID.rid -> integer
2256
+ # - Process::Sys.getuid -> integer
1600
2257
  # -->
1601
- # Returns the (real) user ID of this process.
2258
+ # Returns the (real) user ID of the current process.
1602
2259
  #
1603
- # Process.uid #=> 501
2260
+ # Process.uid # => 1000
1604
2261
  #
1605
2262
  def self.rid: () -> Integer
1606
2263
 
@@ -1628,6 +2285,9 @@ module Process::UID
1628
2285
  def self.eid=: (Integer user) -> Integer
1629
2286
  end
1630
2287
 
2288
+ # <!-- rdoc-file=process.c -->
2289
+ # Placeholder for rusage
2290
+ #
1631
2291
  class Process::Tms < Struct[Float]
1632
2292
  end
1633
2293