rbs 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +12 -0
  4. data/.rubocop.yml +15 -0
  5. data/BSDL +22 -0
  6. data/CHANGELOG.md +9 -0
  7. data/COPYING +56 -0
  8. data/Gemfile +6 -0
  9. data/README.md +93 -0
  10. data/Rakefile +142 -0
  11. data/bin/annotate-with-rdoc +157 -0
  12. data/bin/console +14 -0
  13. data/bin/query-rdoc +103 -0
  14. data/bin/setup +10 -0
  15. data/bin/sort +89 -0
  16. data/bin/test_runner.rb +16 -0
  17. data/docs/CONTRIBUTING.md +97 -0
  18. data/docs/sigs.md +148 -0
  19. data/docs/stdlib.md +152 -0
  20. data/docs/syntax.md +528 -0
  21. data/exe/rbs +7 -0
  22. data/lib/rbs.rb +64 -0
  23. data/lib/rbs/ast/annotation.rb +27 -0
  24. data/lib/rbs/ast/comment.rb +27 -0
  25. data/lib/rbs/ast/declarations.rb +395 -0
  26. data/lib/rbs/ast/members.rb +362 -0
  27. data/lib/rbs/buffer.rb +50 -0
  28. data/lib/rbs/builtin_names.rb +55 -0
  29. data/lib/rbs/cli.rb +558 -0
  30. data/lib/rbs/constant.rb +26 -0
  31. data/lib/rbs/constant_table.rb +150 -0
  32. data/lib/rbs/definition.rb +170 -0
  33. data/lib/rbs/definition_builder.rb +919 -0
  34. data/lib/rbs/environment.rb +281 -0
  35. data/lib/rbs/environment_loader.rb +136 -0
  36. data/lib/rbs/environment_walker.rb +124 -0
  37. data/lib/rbs/errors.rb +187 -0
  38. data/lib/rbs/location.rb +102 -0
  39. data/lib/rbs/method_type.rb +123 -0
  40. data/lib/rbs/namespace.rb +91 -0
  41. data/lib/rbs/parser.y +1344 -0
  42. data/lib/rbs/prototype/rb.rb +553 -0
  43. data/lib/rbs/prototype/rbi.rb +587 -0
  44. data/lib/rbs/prototype/runtime.rb +381 -0
  45. data/lib/rbs/substitution.rb +46 -0
  46. data/lib/rbs/test.rb +26 -0
  47. data/lib/rbs/test/errors.rb +61 -0
  48. data/lib/rbs/test/hook.rb +294 -0
  49. data/lib/rbs/test/setup.rb +58 -0
  50. data/lib/rbs/test/spy.rb +325 -0
  51. data/lib/rbs/test/test_helper.rb +183 -0
  52. data/lib/rbs/test/type_check.rb +254 -0
  53. data/lib/rbs/type_name.rb +70 -0
  54. data/lib/rbs/types.rb +936 -0
  55. data/lib/rbs/variance_calculator.rb +138 -0
  56. data/lib/rbs/vendorer.rb +47 -0
  57. data/lib/rbs/version.rb +3 -0
  58. data/lib/rbs/writer.rb +269 -0
  59. data/lib/ruby/signature.rb +7 -0
  60. data/rbs.gemspec +46 -0
  61. data/stdlib/abbrev/abbrev.rbs +60 -0
  62. data/stdlib/base64/base64.rbs +71 -0
  63. data/stdlib/benchmark/benchmark.rbs +372 -0
  64. data/stdlib/builtin/array.rbs +1997 -0
  65. data/stdlib/builtin/basic_object.rbs +280 -0
  66. data/stdlib/builtin/binding.rbs +177 -0
  67. data/stdlib/builtin/builtin.rbs +45 -0
  68. data/stdlib/builtin/class.rbs +145 -0
  69. data/stdlib/builtin/comparable.rbs +116 -0
  70. data/stdlib/builtin/complex.rbs +400 -0
  71. data/stdlib/builtin/constants.rbs +37 -0
  72. data/stdlib/builtin/data.rbs +5 -0
  73. data/stdlib/builtin/deprecated.rbs +2 -0
  74. data/stdlib/builtin/dir.rbs +413 -0
  75. data/stdlib/builtin/encoding.rbs +607 -0
  76. data/stdlib/builtin/enumerable.rbs +404 -0
  77. data/stdlib/builtin/enumerator.rbs +260 -0
  78. data/stdlib/builtin/errno.rbs +781 -0
  79. data/stdlib/builtin/errors.rbs +582 -0
  80. data/stdlib/builtin/exception.rbs +194 -0
  81. data/stdlib/builtin/false_class.rbs +40 -0
  82. data/stdlib/builtin/fiber.rbs +68 -0
  83. data/stdlib/builtin/fiber_error.rbs +12 -0
  84. data/stdlib/builtin/file.rbs +1076 -0
  85. data/stdlib/builtin/file_test.rbs +59 -0
  86. data/stdlib/builtin/float.rbs +696 -0
  87. data/stdlib/builtin/gc.rbs +243 -0
  88. data/stdlib/builtin/hash.rbs +1029 -0
  89. data/stdlib/builtin/integer.rbs +707 -0
  90. data/stdlib/builtin/io.rbs +683 -0
  91. data/stdlib/builtin/kernel.rbs +576 -0
  92. data/stdlib/builtin/marshal.rbs +161 -0
  93. data/stdlib/builtin/match_data.rbs +271 -0
  94. data/stdlib/builtin/math.rbs +369 -0
  95. data/stdlib/builtin/method.rbs +185 -0
  96. data/stdlib/builtin/module.rbs +1104 -0
  97. data/stdlib/builtin/nil_class.rbs +82 -0
  98. data/stdlib/builtin/numeric.rbs +409 -0
  99. data/stdlib/builtin/object.rbs +824 -0
  100. data/stdlib/builtin/proc.rbs +429 -0
  101. data/stdlib/builtin/process.rbs +1227 -0
  102. data/stdlib/builtin/random.rbs +267 -0
  103. data/stdlib/builtin/range.rbs +226 -0
  104. data/stdlib/builtin/rational.rbs +424 -0
  105. data/stdlib/builtin/rb_config.rbs +57 -0
  106. data/stdlib/builtin/regexp.rbs +1083 -0
  107. data/stdlib/builtin/ruby_vm.rbs +14 -0
  108. data/stdlib/builtin/signal.rbs +55 -0
  109. data/stdlib/builtin/string.rbs +1901 -0
  110. data/stdlib/builtin/string_io.rbs +284 -0
  111. data/stdlib/builtin/struct.rbs +40 -0
  112. data/stdlib/builtin/symbol.rbs +228 -0
  113. data/stdlib/builtin/thread.rbs +1108 -0
  114. data/stdlib/builtin/thread_group.rbs +23 -0
  115. data/stdlib/builtin/time.rbs +1047 -0
  116. data/stdlib/builtin/trace_point.rbs +290 -0
  117. data/stdlib/builtin/true_class.rbs +46 -0
  118. data/stdlib/builtin/unbound_method.rbs +153 -0
  119. data/stdlib/builtin/warning.rbs +17 -0
  120. data/stdlib/coverage/coverage.rbs +62 -0
  121. data/stdlib/csv/csv.rbs +773 -0
  122. data/stdlib/erb/erb.rbs +392 -0
  123. data/stdlib/find/find.rbs +40 -0
  124. data/stdlib/ipaddr/ipaddr.rbs +247 -0
  125. data/stdlib/json/json.rbs +335 -0
  126. data/stdlib/pathname/pathname.rbs +1093 -0
  127. data/stdlib/prime/integer-extension.rbs +23 -0
  128. data/stdlib/prime/prime.rbs +188 -0
  129. data/stdlib/securerandom/securerandom.rbs +9 -0
  130. data/stdlib/set/set.rbs +301 -0
  131. data/stdlib/tmpdir/tmpdir.rbs +53 -0
  132. metadata +292 -0
@@ -0,0 +1,429 @@
1
+ # A `Proc` object is an encapsulation of a block of code, which can be
2
+ # stored in a local variable, passed to a method or another
3
+ # [Proc](Proc), and can be called.
4
+ # [Proc](Proc) is an essential concept in Ruby and a
5
+ # core of its functional programming features.
6
+ #
7
+ # ```ruby
8
+ # square = Proc.new {|x| x**2 }
9
+ #
10
+ # square.call(3) #=> 9
11
+ # # shorthands:
12
+ # square.(3) #=> 9
13
+ # square[3] #=> 9
14
+ # ```
15
+ #
16
+ # [Proc](Proc) objects are *closures* , meaning they
17
+ # remember and can use the entire context in which they were created.
18
+ #
19
+ # ```ruby
20
+ # def gen_times(factor)
21
+ # Proc.new {|n| n*factor } # remembers the value of factor at the moment of creation
22
+ # end
23
+ #
24
+ # times3 = gen_times(3)
25
+ # times5 = gen_times(5)
26
+ #
27
+ # times3.call(12) #=> 36
28
+ # times5.call(5) #=> 25
29
+ # times3.call(times5.call(4)) #=> 60
30
+ # ```
31
+ #
32
+ #
33
+ # There are several methods to create a [Proc](Proc)
34
+ #
35
+ # - Use the [Proc](Proc) class constructor:
36
+ #
37
+ # ```ruby
38
+ # proc1 = Proc.new {|x| x**2 }
39
+ # ```
40
+ #
41
+ # - Use the
42
+ # [Kernel\#proc](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-proc)
43
+ # method as a shorthand of
44
+ # [::new](Proc#method-c-new):
45
+ #
46
+ # ```ruby
47
+ # proc2 = proc {|x| x**2 }
48
+ # ```
49
+ #
50
+ # - Receiving a block of code into proc argument (note the `&` ):
51
+ #
52
+ # ```ruby
53
+ # def make_proc(&block)
54
+ # block
55
+ # end
56
+ #
57
+ # proc3 = make_proc {|x| x**2 }
58
+ # ```
59
+ #
60
+ # - Construct a proc with lambda semantics using the
61
+ # [Kernel\#lambda](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-lambda)
62
+ # method (see below for explanations about lambdas):
63
+ #
64
+ # ```ruby
65
+ # lambda1 = lambda {|x| x**2 }
66
+ # ```
67
+ #
68
+ # - Use the Lambda literal syntax (also constructs a proc with lambda
69
+ # semantics):
70
+ #
71
+ # ```ruby
72
+ # lambda2 = ->(x) { x**2 }
73
+ # ```
74
+ #
75
+ #
76
+ # Procs are coming in two flavors: lambda and non-lambda (regular procs).
77
+ # Differences are:
78
+ #
79
+ # - In lambdas, `return` means exit from this lambda;
80
+ #
81
+ # - In regular procs, `return` means exit from embracing method (and
82
+ # will throw `LocalJumpError` if invoked outside the method);
83
+ #
84
+ # - In lambdas, arguments are treated in the same way as in methods:
85
+ # strict, with `ArgumentError` for mismatching argument number, and no
86
+ # additional argument processing;
87
+ #
88
+ # - Regular procs accept arguments more generously: missing arguments
89
+ # are filled with `nil`, single
90
+ # [Array](https://ruby-doc.org/core-2.6.3/Array.html) arguments are
91
+ # deconstructed if the proc has multiple arguments, and there is no
92
+ # error raised on extra arguments.
93
+ #
94
+ # Examples:
95
+ #
96
+ # ```ruby
97
+ # p = proc {|x, y| "x=#{x}, y=#{y}" }
98
+ # p.call(1, 2) #=> "x=1, y=2"
99
+ # p.call([1, 2]) #=> "x=1, y=2", array deconstructed
100
+ # p.call(1, 2, 8) #=> "x=1, y=2", extra argument discarded
101
+ # p.call(1) #=> "x=1, y=", nil substituted instead of error
102
+ #
103
+ # l = lambda {|x, y| "x=#{x}, y=#{y}" }
104
+ # l.call(1, 2) #=> "x=1, y=2"
105
+ # l.call([1, 2]) # ArgumentError: wrong number of arguments (given 1, expected 2)
106
+ # l.call(1, 2, 8) # ArgumentError: wrong number of arguments (given 3, expected 2)
107
+ # l.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
108
+ #
109
+ # def test_return
110
+ # -> { return 3 }.call # just returns from lambda into method body
111
+ # proc { return 4 }.call # returns from method
112
+ # return 5
113
+ # end
114
+ #
115
+ # test_return # => 4, return from proc
116
+ # ```
117
+ #
118
+ # Lambdas are useful as self-sufficient functions, in particular useful as
119
+ # arguments to higher-order functions, behaving exactly like Ruby methods.
120
+ #
121
+ # Procs are useful for implementing iterators:
122
+ #
123
+ # ```ruby
124
+ # def test
125
+ # [[1, 2], [3, 4], [5, 6]].map {|a, b| return a if a + b > 10 }
126
+ # # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127
+ # end
128
+ # ```
129
+ #
130
+ # Inside `map`, the block of code is treated as a regular (non-lambda)
131
+ # proc, which means that the internal arrays will be deconstructed to
132
+ # pairs of arguments, and `return` will exit from the method `test` . That
133
+ # would not be possible with a stricter lambda.
134
+ #
135
+ # You can tell a lambda from a regular proc by using the
136
+ # [lambda?](Proc#method-i-lambda-3F) instance method.
137
+ #
138
+ # Lambda semantics is typically preserved during the proc lifetime,
139
+ # including `&` -deconstruction to a block of code:
140
+ #
141
+ # ```ruby
142
+ # p = proc {|x, y| x }
143
+ # l = lambda {|x, y| x }
144
+ # [[1, 2], [3, 4]].map(&p) #=> [1, 2]
145
+ # [[1, 2], [3, 4]].map(&l) # ArgumentError: wrong number of arguments (given 1, expected 2)
146
+ # ```
147
+ #
148
+ # The only exception is dynamic method definition: even if defined by
149
+ # passing a non-lambda proc, methods still have normal semantics of
150
+ # argument checking.
151
+ #
152
+ # ```ruby
153
+ # class C
154
+ # define_method(:e, &proc {})
155
+ # end
156
+ # C.new.e(1,2) #=> ArgumentError
157
+ # C.new.method(:e).to_proc.lambda? #=> true
158
+ # ```
159
+ #
160
+ # This exception ensures that methods never have unusual argument passing
161
+ # conventions, and makes it easy to have wrappers defining methods that
162
+ # behave as usual.
163
+ #
164
+ # ```ruby
165
+ # class C
166
+ # def self.def2(name, &body)
167
+ # define_method(name, &body)
168
+ # end
169
+ #
170
+ # def2(:f) {}
171
+ # end
172
+ # C.new.f(1,2) #=> ArgumentError
173
+ # ```
174
+ #
175
+ # The wrapper *def2* receives `body` as a non-lambda proc, yet defines a
176
+ # method which has normal semantics.
177
+ #
178
+ #
179
+ # Any object that implements the `to_proc` method can be converted into a
180
+ # proc by the `&` operator, and therefore con be consumed by iterators.
181
+ #
182
+ # ```ruby
183
+ # class Greater
184
+ # def initialize(greating)
185
+ # @greating = greating
186
+ # end
187
+ #
188
+ # def to_proc
189
+ # proc {|name| "#{@greating}, #{name}!" }
190
+ # end
191
+ # end
192
+ #
193
+ # hi = Greater.new("Hi")
194
+ # hey = Greater.new("Hey")
195
+ # ["Bob", "Jane"].map(&hi) #=> ["Hi, Bob!", "Hi, Jane!"]
196
+ # ["Bob", "Jane"].map(&hey) #=> ["Hey, Bob!", "Hey, Jane!"]
197
+ # ```
198
+ #
199
+ # Of the Ruby core classes, this method is implemented by
200
+ # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html),
201
+ # [Method](https://ruby-doc.org/core-2.6.3/Method.html), and
202
+ # [Hash](https://ruby-doc.org/core-2.6.3/Hash.html).
203
+ #
204
+ # :to_s.to_proc.call(1) #=> "1"
205
+ # [1, 2].map(&:to_s) #=> ["1", "2"]
206
+ #
207
+ # method(:puts).to_proc.call(1) # prints 1
208
+ # [1, 2].each(&method(:puts)) # prints 1, 2
209
+ #
210
+ # {test: 1}.to_proc.call(:test) #=> 1
211
+ # %i[test many keys].map(&{test: 1}) #=> [1, nil, nil]
212
+ class Proc < Object
213
+ # Returns the number of mandatory arguments. If the block is declared to
214
+ # take no arguments, returns 0. If the block is known to take exactly n
215
+ # arguments, returns n. If the block has optional arguments, returns -n-1,
216
+ # where n is the number of mandatory arguments, with the exception for
217
+ # blocks that are not lambdas and have only a finite number of optional
218
+ # arguments; in this latter case, returns n. Keyword arguments will be
219
+ # considered as a single additional argument, that argument being
220
+ # mandatory if any keyword argument is mandatory. A `proc` with no
221
+ # argument declarations is the same as a block declaring `||` as its
222
+ # arguments.
223
+ #
224
+ # proc {}.arity #=> 0
225
+ # proc { || }.arity #=> 0
226
+ # proc { |a| }.arity #=> 1
227
+ # proc { |a, b| }.arity #=> 2
228
+ # proc { |a, b, c| }.arity #=> 3
229
+ # proc { |*a| }.arity #=> -1
230
+ # proc { |a, *b| }.arity #=> -2
231
+ # proc { |a, *b, c| }.arity #=> -3
232
+ # proc { |x:, y:, z:0| }.arity #=> 1
233
+ # proc { |*a, x:, y:0| }.arity #=> -2
234
+ #
235
+ # proc { |a=0| }.arity #=> 0
236
+ # lambda { |a=0| }.arity #=> -1
237
+ # proc { |a=0, b| }.arity #=> 1
238
+ # lambda { |a=0, b| }.arity #=> -2
239
+ # proc { |a=0, b=0| }.arity #=> 0
240
+ # lambda { |a=0, b=0| }.arity #=> -1
241
+ # proc { |a, b=0| }.arity #=> 1
242
+ # lambda { |a, b=0| }.arity #=> -2
243
+ # proc { |(a, b), c=0| }.arity #=> 1
244
+ # lambda { |(a, b), c=0| }.arity #=> -2
245
+ # proc { |a, x:0, y:0| }.arity #=> 1
246
+ # lambda { |a, x:0, y:0| }.arity #=> -2
247
+ def arity: () -> Integer
248
+
249
+ # Returns the binding associated with *prc* .
250
+ #
251
+ # ```ruby
252
+ # def fred(param)
253
+ # proc {}
254
+ # end
255
+ #
256
+ # b = fred(99)
257
+ # eval("param", b.binding) #=> 99
258
+ # ```
259
+ def binding: () -> Binding
260
+
261
+ def call: (*untyped arg0) -> untyped
262
+
263
+ def []: (*untyped arg0) -> untyped
264
+
265
+ def curry: (?Integer arity) -> Proc
266
+
267
+ # Returns a hash value corresponding to proc body.
268
+ #
269
+ # See also Object\#hash.
270
+ def hash: () -> Integer
271
+
272
+ def initialize: () -> void
273
+ | () { (*untyped) -> untyped } -> void
274
+
275
+ # Returns `true` for a [Proc](Proc.downloaded.ruby_doc) object for which
276
+ # argument handling is rigid. Such procs are typically generated by
277
+ # `lambda` .
278
+ #
279
+ # A [Proc](Proc.downloaded.ruby_doc) object generated by `proc` ignores
280
+ # extra arguments.
281
+ #
282
+ # ```ruby
283
+ # proc {|a,b| [a,b] }.call(1,2,3) #=> [1,2]
284
+ # ```
285
+ #
286
+ # It provides `nil` for missing arguments.
287
+ #
288
+ # ```ruby
289
+ # proc {|a,b| [a,b] }.call(1) #=> [1,nil]
290
+ # ```
291
+ #
292
+ # It expands a single array argument.
293
+ #
294
+ # ```ruby
295
+ # proc {|a,b| [a,b] }.call([1,2]) #=> [1,2]
296
+ # ```
297
+ #
298
+ # A [Proc](Proc.downloaded.ruby_doc) object generated by `lambda` doesn’t
299
+ # have such tricks.
300
+ #
301
+ # ```ruby
302
+ # lambda {|a,b| [a,b] }.call(1,2,3) #=> ArgumentError
303
+ # lambda {|a,b| [a,b] }.call(1) #=> ArgumentError
304
+ # lambda {|a,b| [a,b] }.call([1,2]) #=> ArgumentError
305
+ # ```
306
+ #
307
+ # [\#lambda?](Proc.downloaded.ruby_doc#method-i-lambda-3F) is a predicate
308
+ # for the tricks. It returns `true` if no tricks apply.
309
+ #
310
+ # ```ruby
311
+ # lambda {}.lambda? #=> true
312
+ # proc {}.lambda? #=> false
313
+ # ```
314
+ #
315
+ # [::new](Proc.downloaded.ruby_doc#method-c-new) is the same as `proc` .
316
+ #
317
+ # ```ruby
318
+ # Proc.new {}.lambda? #=> false
319
+ # ```
320
+ #
321
+ # `lambda`, `proc` and [::new](Proc.downloaded.ruby_doc#method-c-new)
322
+ # preserve the tricks of a [Proc](Proc.downloaded.ruby_doc) object given
323
+ # by `&` argument.
324
+ #
325
+ # ```ruby
326
+ # lambda(&lambda {}).lambda? #=> true
327
+ # proc(&lambda {}).lambda? #=> true
328
+ # Proc.new(&lambda {}).lambda? #=> true
329
+ #
330
+ # lambda(&proc {}).lambda? #=> false
331
+ # proc(&proc {}).lambda? #=> false
332
+ # Proc.new(&proc {}).lambda? #=> false
333
+ # ```
334
+ #
335
+ # A [Proc](Proc.downloaded.ruby_doc) object generated by `&` argument has
336
+ # the tricks
337
+ #
338
+ # ```ruby
339
+ # def n(&b) b.lambda? end
340
+ # n {} #=> false
341
+ # ```
342
+ #
343
+ # The `&` argument preserves the tricks if a
344
+ # [Proc](Proc.downloaded.ruby_doc) object is given by `&` argument.
345
+ #
346
+ # ```ruby
347
+ # n(&lambda {}) #=> true
348
+ # n(&proc {}) #=> false
349
+ # n(&Proc.new {}) #=> false
350
+ # ```
351
+ #
352
+ # A [Proc](Proc.downloaded.ruby_doc) object converted from a method has no
353
+ # tricks.
354
+ #
355
+ # ```ruby
356
+ # def m() end
357
+ # method(:m).to_proc.lambda? #=> true
358
+ #
359
+ # n(&method(:m)) #=> true
360
+ # n(&method(:m).to_proc) #=> true
361
+ # ```
362
+ #
363
+ # `define_method` is treated the same as method definition. The defined
364
+ # method has no tricks.
365
+ #
366
+ # ```ruby
367
+ # class C
368
+ # define_method(:d) {}
369
+ # end
370
+ # C.new.d(1,2) #=> ArgumentError
371
+ # C.new.method(:d).to_proc.lambda? #=> true
372
+ # ```
373
+ #
374
+ # `define_method` always defines a method without the tricks, even if a
375
+ # non-lambda [Proc](Proc.downloaded.ruby_doc) object is given. This is the
376
+ # only exception for which the tricks are not preserved.
377
+ #
378
+ # ```ruby
379
+ # class C
380
+ # define_method(:e, &proc {})
381
+ # end
382
+ # C.new.e(1,2) #=> ArgumentError
383
+ # C.new.method(:e).to_proc.lambda? #=> true
384
+ # ```
385
+ #
386
+ # This exception ensures that methods never have tricks and makes it easy
387
+ # to have wrappers to define methods that behave as usual.
388
+ #
389
+ # ```ruby
390
+ # class C
391
+ # def self.def2(name, &body)
392
+ # define_method(name, &body)
393
+ # end
394
+ #
395
+ # def2(:f) {}
396
+ # end
397
+ # C.new.f(1,2) #=> ArgumentError
398
+ # ```
399
+ #
400
+ # The wrapper *def2* defines a method which has no tricks.
401
+ def lambda?: () -> bool
402
+
403
+ # Returns the parameter information of this proc.
404
+ #
405
+ # ```ruby
406
+ # prc = lambda{|x, y=42, *other|}
407
+ # prc.parameters #=> [[:req, :x], [:opt, :y], [:rest, :other]]
408
+ # ```
409
+ def parameters: () -> ::Array[[ Symbol, Symbol ]]
410
+
411
+ # Returns the Ruby source filename and line number containing this proc or
412
+ # `nil` if this proc was not defined in Ruby (i.e. native).
413
+ def source_location: () -> [ String, Integer ]
414
+
415
+ # Part of the protocol for converting objects to `Proc` objects. Instances
416
+ # of class `Proc` simply return themselves.
417
+ def to_proc: () -> self
418
+
419
+ # Returns the unique identifier for this proc, along with an indication of
420
+ # where the proc was defined.
421
+ #
422
+ #
423
+ #
424
+ # Also aliased as: [inspect](Proc.downloaded.ruby_doc#method-i-inspect)
425
+ def to_s: () -> String
426
+
427
+ # Alias for: [to\_s](Proc.downloaded.ruby_doc#method-i-to_s)
428
+ def inspect: () -> String
429
+ end
@@ -0,0 +1,1227 @@
1
+ # The module contains several groups of functionality for handling OS processes:
2
+ #
3
+ # * Low-level property introspection and management of the current process,
4
+ # like Process.argv0, Process.pid;
5
+ # * Low-level introspection of other processes, like Process.getpgid,
6
+ # Process.getpriority;
7
+ # * Management of the current process: Process.abort, Process.exit,
8
+ # Process.daemon, etc. (for convenience, most of those are also available as
9
+ # global functions and module functions of Kernel);
10
+ # * Creation and management of child processes: Process.fork, Process.spawn,
11
+ # and related methods;
12
+ # * Management of low-level system clock: Process.times and
13
+ # Process.clock_gettime, which could be important for proper benchmarking
14
+ # and other elapsed time measurement tasks.
15
+ #
16
+ #
17
+ module Process
18
+ # Returns the name of the script being executed. The value is not affected by
19
+ # assigning a new value to $0.
20
+ #
21
+ # This method first appeared in Ruby 2.1 to serve as a global variable free
22
+ # means to get the script name.
23
+ #
24
+ def self.argv0: () -> String
25
+
26
+ # Returns the time resolution returned by POSIX clock_getres() function.
27
+ #
28
+ # `clock_id` specifies a kind of clock. See the document of
29
+ # `Process.clock_gettime` for details.
30
+ #
31
+ # `clock_id` can be a symbol as `Process.clock_gettime`. However the result may
32
+ # not be accurate. For example,
33
+ # `Process.clock_getres(:GETTIMEOFDAY_BASED_CLOCK_REALTIME)` returns 1.0e-06
34
+ # which means 1 microsecond, but actual resolution can be more coarse.
35
+ #
36
+ # If the given `clock_id` is not supported, Errno::EINVAL is raised.
37
+ #
38
+ # `unit` specifies a type of the return value. `Process.clock_getres` accepts
39
+ # `unit` as `Process.clock_gettime`. The default value, `:float_second`, is also
40
+ # same as `Process.clock_gettime`.
41
+ #
42
+ # `Process.clock_getres` also accepts `:hertz` as `unit`. `:hertz` means a the
43
+ # reciprocal of `:float_second`.
44
+ #
45
+ # `:hertz` can be used to obtain the exact value of the clock ticks per second
46
+ # for times() function and CLOCKS_PER_SEC for clock() function.
47
+ #
48
+ # `Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)` returns
49
+ # the clock ticks per second.
50
+ #
51
+ # `Process.clock_getres(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)` returns
52
+ # CLOCKS_PER_SEC.
53
+ #
54
+ # p Process.clock_getres(Process::CLOCK_MONOTONIC)
55
+ # #=> 1.0e-09
56
+ #
57
+ def self.clock_getres: (Symbol | Integer clock_id, ?Symbol unit) -> (Float | Integer)
58
+
59
+ # Returns a time returned by POSIX clock_gettime() function.
60
+ #
61
+ # p Process.clock_gettime(Process::CLOCK_MONOTONIC)
62
+ # #=> 896053.968060096
63
+ #
64
+ # `clock_id` specifies a kind of clock. It is specified as a constant which
65
+ # begins with `Process::CLOCK_` such as Process::CLOCK_REALTIME and
66
+ # Process::CLOCK_MONOTONIC.
67
+ #
68
+ # The supported constants depends on OS and version. Ruby provides following
69
+ # types of `clock_id` if available.
70
+ #
71
+ # CLOCK_REALTIME
72
+ # : SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS
73
+ # 10.12
74
+ # CLOCK_MONOTONIC
75
+ # : SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 3.4, macOS
76
+ # 10.12
77
+ # CLOCK_PROCESS_CPUTIME_ID
78
+ # : SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3, OpenBSD 5.4, macOS 10.12
79
+ # CLOCK_THREAD_CPUTIME_ID
80
+ # : SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD 5.4, macOS 10.12
81
+ # CLOCK_VIRTUAL
82
+ # : FreeBSD 3.0, OpenBSD 2.1
83
+ # CLOCK_PROF
84
+ # : FreeBSD 3.0, OpenBSD 2.1
85
+ # CLOCK_REALTIME_FAST
86
+ # : FreeBSD 8.1
87
+ # CLOCK_REALTIME_PRECISE
88
+ # : FreeBSD 8.1
89
+ # CLOCK_REALTIME_COARSE
90
+ # : Linux 2.6.32
91
+ # CLOCK_REALTIME_ALARM
92
+ # : Linux 3.0
93
+ # CLOCK_MONOTONIC_FAST
94
+ # : FreeBSD 8.1
95
+ # CLOCK_MONOTONIC_PRECISE
96
+ # : FreeBSD 8.1
97
+ # CLOCK_MONOTONIC_COARSE
98
+ # : Linux 2.6.32
99
+ # CLOCK_MONOTONIC_RAW
100
+ # : Linux 2.6.28, macOS 10.12
101
+ # CLOCK_MONOTONIC_RAW_APPROX
102
+ # : macOS 10.12
103
+ # CLOCK_BOOTTIME
104
+ # : Linux 2.6.39
105
+ # CLOCK_BOOTTIME_ALARM
106
+ # : Linux 3.0
107
+ # CLOCK_UPTIME
108
+ # : FreeBSD 7.0, OpenBSD 5.5
109
+ # CLOCK_UPTIME_FAST
110
+ # : FreeBSD 8.1
111
+ # CLOCK_UPTIME_RAW
112
+ # : macOS 10.12
113
+ # CLOCK_UPTIME_RAW_APPROX
114
+ # : macOS 10.12
115
+ # CLOCK_UPTIME_PRECISE
116
+ # : FreeBSD 8.1
117
+ # CLOCK_SECOND
118
+ # : FreeBSD 8.1
119
+ # CLOCK_TAI
120
+ # : Linux 3.10
121
+ #
122
+ #
123
+ # Note that SUS stands for Single Unix Specification. SUS contains POSIX and
124
+ # clock_gettime is defined in the POSIX part. SUS defines CLOCK_REALTIME
125
+ # mandatory but CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID and
126
+ # CLOCK_THREAD_CPUTIME_ID are optional.
127
+ #
128
+ # Also, several symbols are accepted as `clock_id`. There are emulations for
129
+ # clock_gettime().
130
+ #
131
+ # For example, Process::CLOCK_REALTIME is defined as
132
+ # `:GETTIMEOFDAY_BASED_CLOCK_REALTIME` when clock_gettime() is not available.
133
+ #
134
+ # Emulations for `CLOCK_REALTIME`:
135
+ # :GETTIMEOFDAY_BASED_CLOCK_REALTIME
136
+ # : Use gettimeofday() defined by SUS. (SUSv4 obsoleted it, though.) The
137
+ # resolution is 1 microsecond.
138
+ # :TIME_BASED_CLOCK_REALTIME
139
+ # : Use time() defined by ISO C. The resolution is 1 second.
140
+ #
141
+ #
142
+ # Emulations for `CLOCK_MONOTONIC`:
143
+ # :MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
144
+ # : Use mach_absolute_time(), available on Darwin. The resolution is CPU
145
+ # dependent.
146
+ # :TIMES_BASED_CLOCK_MONOTONIC
147
+ # : Use the result value of times() defined by POSIX. POSIX defines it as
148
+ # "times() shall return the elapsed real time, in clock ticks, since an
149
+ # arbitrary point in the past (for example, system start-up time)". For
150
+ # example, GNU/Linux returns a value based on jiffies and it is monotonic.
151
+ # However, 4.4BSD uses gettimeofday() and it is not monotonic. (FreeBSD uses
152
+ # clock_gettime(CLOCK_MONOTONIC) instead, though.) The resolution is the
153
+ # clock tick. "getconf CLK_TCK" command shows the clock ticks per second.
154
+ # (The clock ticks per second is defined by HZ macro in older systems.) If
155
+ # it is 100 and clock_t is 32 bits integer type, the resolution is 10
156
+ # millisecond and cannot represent over 497 days.
157
+ #
158
+ #
159
+ # Emulations for `CLOCK_PROCESS_CPUTIME_ID`:
160
+ # :GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
161
+ # : Use getrusage() defined by SUS. getrusage() is used with RUSAGE_SELF to
162
+ # obtain the time only for the calling process (excluding the time for child
163
+ # processes). The result is addition of user time (ru_utime) and system time
164
+ # (ru_stime). The resolution is 1 microsecond.
165
+ # :TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
166
+ # : Use times() defined by POSIX. The result is addition of user time
167
+ # (tms_utime) and system time (tms_stime). tms_cutime and tms_cstime are
168
+ # ignored to exclude the time for child processes. The resolution is the
169
+ # clock tick. "getconf CLK_TCK" command shows the clock ticks per second.
170
+ # (The clock ticks per second is defined by HZ macro in older systems.) If
171
+ # it is 100, the resolution is 10 millisecond.
172
+ # :CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
173
+ # : Use clock() defined by ISO C. The resolution is 1/CLOCKS_PER_SEC.
174
+ # CLOCKS_PER_SEC is the C-level macro defined by time.h. SUS defines
175
+ # CLOCKS_PER_SEC is 1000000. Non-Unix systems may define it a different
176
+ # value, though. If CLOCKS_PER_SEC is 1000000 as SUS, the resolution is 1
177
+ # microsecond. If CLOCKS_PER_SEC is 1000000 and clock_t is 32 bits integer
178
+ # type, it cannot represent over 72 minutes.
179
+ #
180
+ #
181
+ # If the given `clock_id` is not supported, Errno::EINVAL is raised.
182
+ #
183
+ # `unit` specifies a type of the return value.
184
+ #
185
+ # :float_second
186
+ # : number of seconds as a float (default)
187
+ # :float_millisecond
188
+ # : number of milliseconds as a float
189
+ # :float_microsecond
190
+ # : number of microseconds as a float
191
+ # :second
192
+ # : number of seconds as an integer
193
+ # :millisecond
194
+ # : number of milliseconds as an integer
195
+ # :microsecond
196
+ # : number of microseconds as an integer
197
+ # :nanosecond
198
+ # : number of nanoseconds as an integer
199
+ #
200
+ #
201
+ # The underlying function, clock_gettime(), returns a number of nanoseconds.
202
+ # Float object (IEEE 754 double) is not enough to represent the return value for
203
+ # CLOCK_REALTIME. If the exact nanoseconds value is required, use `:nanoseconds`
204
+ # as the `unit`.
205
+ #
206
+ # The origin (zero) of the returned value varies. For example, system start up
207
+ # time, process start up time, the Epoch, etc.
208
+ #
209
+ # The origin in CLOCK_REALTIME is defined as the Epoch (1970-01-01 00:00:00
210
+ # UTC). But some systems count leap seconds and others doesn't. So the result
211
+ # can be interpreted differently across systems. Time.now is recommended over
212
+ # CLOCK_REALTIME.
213
+ #
214
+ def self.clock_gettime: (Symbol | Integer clock_id, ?Symbol unit) -> (Float | Integer)
215
+
216
+ # Detach the process from controlling terminal and run in the background as
217
+ # system daemon. Unless the argument nochdir is true (i.e. non false), it
218
+ # changes the current working directory to the root ("/"). Unless the argument
219
+ # noclose is true, daemon() will redirect standard input, standard output and
220
+ # standard error to /dev/null. Return zero on success, or raise one of Errno::*.
221
+ #
222
+ def self.daemon: (?untyped nochdir, ?untyped noclose) -> Integer
223
+
224
+ # Some operating systems retain the status of terminated child processes until
225
+ # the parent collects that status (normally using some variant of `wait()`). If
226
+ # the parent never collects this status, the child stays around as a *zombie*
227
+ # process. Process::detach prevents this by setting up a separate Ruby thread
228
+ # whose sole job is to reap the status of the process *pid* when it terminates.
229
+ # Use #detach only when you do not intend to explicitly wait for the child to
230
+ # terminate.
231
+ #
232
+ # The waiting thread returns the exit status of the detached process when it
233
+ # terminates, so you can use Thread#join to know the result. If specified *pid*
234
+ # is not a valid child process ID, the thread returns `nil` immediately.
235
+ #
236
+ # The waiting thread has #pid method which returns the pid.
237
+ #
238
+ # In this first example, we don't reap the first child process, so it appears as
239
+ # a zombie in the process status display.
240
+ #
241
+ # p1 = fork { sleep 0.1 }
242
+ # p2 = fork { sleep 0.2 }
243
+ # Process.waitpid(p2)
244
+ # sleep 2
245
+ # system("ps -ho pid,state -p #{p1}")
246
+ #
247
+ # *produces:*
248
+ #
249
+ # 27389 Z
250
+ #
251
+ # In the next example, Process::detach is used to reap the child automatically.
252
+ #
253
+ # p1 = fork { sleep 0.1 }
254
+ # p2 = fork { sleep 0.2 }
255
+ # Process.detach(p1)
256
+ # Process.waitpid(p2)
257
+ # sleep 2
258
+ # system("ps -ho pid,state -p #{p1}")
259
+ #
260
+ # *(produces no output)*
261
+ #
262
+ def self.detach: (Integer pid) -> Thread
263
+
264
+ # Returns the effective group ID for this process. Not available on all
265
+ # platforms.
266
+ #
267
+ # Process.egid #=> 500
268
+ #
269
+ def self.egid: () -> Integer
270
+
271
+ # Sets the effective group ID for this process. Not available on all platforms.
272
+ #
273
+ def self.egid=: (Integer arg0) -> Integer
274
+
275
+ # Returns the effective user ID for this process.
276
+ #
277
+ # Process.euid #=> 501
278
+ #
279
+ def self.euid: () -> Integer
280
+
281
+ # Sets the effective user ID for this process. Not available on all platforms.
282
+ #
283
+ def self.euid=: (Integer arg0) -> Integer
284
+
285
+ # Returns the process group ID for the given process id. Not available on all
286
+ # platforms.
287
+ #
288
+ # Process.getpgid(Process.ppid()) #=> 25527
289
+ #
290
+ def self.getpgid: (Integer pid) -> Integer
291
+
292
+ # Returns the process group ID for this process. Not available on all platforms.
293
+ #
294
+ # Process.getpgid(0) #=> 25527
295
+ # Process.getpgrp #=> 25527
296
+ #
297
+ def self.getpgrp: () -> Integer
298
+
299
+ # Gets the scheduling priority for specified process, process group, or user.
300
+ # *kind* indicates the kind of entity to find: one of Process::PRIO_PGRP,
301
+ # Process::PRIO_USER, or Process::PRIO_PROCESS. *integer* is an id indicating
302
+ # the particular process, process group, or user (an id of 0 means *current*).
303
+ # Lower priorities are more favorable for scheduling. Not available on all
304
+ # platforms.
305
+ #
306
+ # Process.getpriority(Process::PRIO_USER, 0) #=> 19
307
+ # Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19
308
+ #
309
+ def self.getpriority: (Integer kind, Integer arg0) -> Integer
310
+
311
+ # Gets the resource limit of the process. *cur_limit* means current (soft) limit
312
+ # and *max_limit* means maximum (hard) limit.
313
+ #
314
+ # *resource* indicates the kind of resource to limit. It is specified as a
315
+ # symbol such as `:CORE`, a string such as `"CORE"` or a constant such as
316
+ # Process::RLIMIT_CORE. See Process.setrlimit for details.
317
+ #
318
+ # *cur_limit* and *max_limit* may be Process::RLIM_INFINITY,
319
+ # Process::RLIM_SAVED_MAX or Process::RLIM_SAVED_CUR. See Process.setrlimit and
320
+ # the system getrlimit(2) manual for details.
321
+ #
322
+ def self.getrlimit: (Symbol | String | Integer resource) -> [ Integer, Integer ]
323
+
324
+ # Returns the session ID for the given process id. If not given, return current
325
+ # process sid. Not available on all platforms.
326
+ #
327
+ # Process.getsid() #=> 27422
328
+ # Process.getsid(0) #=> 27422
329
+ # Process.getsid(Process.pid()) #=> 27422
330
+ #
331
+ def self.getsid: (?Integer pid) -> Integer
332
+
333
+ # Returns the (real) group ID for this process.
334
+ #
335
+ # Process.gid #=> 500
336
+ #
337
+ def self.gid: () -> Integer
338
+
339
+ # Sets the group ID for this process.
340
+ #
341
+ def self.gid=: (Integer arg0) -> Integer
342
+
343
+ # Get an Array of the group IDs in the supplemental group access list for this
344
+ # process.
345
+ #
346
+ # Process.groups #=> [27, 6, 10, 11]
347
+ #
348
+ # Note that this method is just a wrapper of getgroups(2). This means that the
349
+ # following characteristics of the result completely depend on your system:
350
+ #
351
+ # * the result is sorted
352
+ # * the result includes effective GIDs
353
+ # * the result does not include duplicated GIDs
354
+ #
355
+ #
356
+ # You can make sure to get a sorted unique GID list of the current process by
357
+ # this expression:
358
+ #
359
+ # Process.groups.uniq.sort
360
+ #
361
+ def self.groups: () -> ::Array[Integer]
362
+
363
+ # Set the supplemental group access list to the given Array of group IDs.
364
+ #
365
+ # Process.groups #=> [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
366
+ # Process.groups = [27, 6, 10, 11] #=> [27, 6, 10, 11]
367
+ # Process.groups #=> [27, 6, 10, 11]
368
+ #
369
+ def self.groups=: (::Array[Integer] arg0) -> ::Array[Integer]
370
+
371
+ # Initializes the supplemental group access list by reading the system group
372
+ # database and using all groups of which the given user is a member. The group
373
+ # with the specified *gid* is also added to the list. Returns the resulting
374
+ # Array of the gids of all the groups in the supplementary group access list.
375
+ # Not available on all platforms.
376
+ #
377
+ # Process.groups #=> [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
378
+ # Process.initgroups( "mgranger", 30 ) #=> [30, 6, 10, 11]
379
+ # Process.groups #=> [30, 6, 10, 11]
380
+ #
381
+ def self.initgroups: (String username, Integer gid) -> ::Array[Integer]
382
+
383
+ # Sends the given signal to the specified process id(s) if *pid* is positive. If
384
+ # *pid* is zero, *signal* is sent to all processes whose group ID is equal to
385
+ # the group ID of the process. If *pid* is negative, results are dependent on
386
+ # the operating system. *signal* may be an integer signal number or a POSIX
387
+ # signal name (either with or without a `SIG` prefix). If *signal* is negative
388
+ # (or starts with a minus sign), kills process groups instead of processes. Not
389
+ # all signals are available on all platforms. The keys and values of Signal.list
390
+ # are known signal names and numbers, respectively.
391
+ #
392
+ # pid = fork do
393
+ # Signal.trap("HUP") { puts "Ouch!"; exit }
394
+ # # ... do some work ...
395
+ # end
396
+ # # ...
397
+ # Process.kill("HUP", pid)
398
+ # Process.wait
399
+ #
400
+ # *produces:*
401
+ #
402
+ # Ouch!
403
+ #
404
+ # If *signal* is an integer but wrong for signal, Errno::EINVAL or RangeError
405
+ # will be raised. Otherwise unless *signal* is a String or a Symbol, and a
406
+ # known signal name, ArgumentError will be raised.
407
+ #
408
+ # Also, Errno::ESRCH or RangeError for invalid *pid*, Errno::EPERM when failed
409
+ # because of no privilege, will be raised. In these cases, signals may have
410
+ # been sent to preceding processes.
411
+ #
412
+ def self.kill: (Integer | Symbol | String signal, *Integer pids) -> Integer
413
+
414
+ # Returns the maximum number of gids allowed in the supplemental group access
415
+ # list.
416
+ #
417
+ # Process.maxgroups #=> 32
418
+ #
419
+ def self.maxgroups: () -> Integer
420
+
421
+ # Sets the maximum number of gids allowed in the supplemental group access list.
422
+ #
423
+ def self.maxgroups=: (Integer arg0) -> Integer
424
+
425
+ # Returns the process id of this process. Not available on all platforms.
426
+ #
427
+ # Process.pid #=> 27415
428
+ #
429
+ def self.pid: () -> Integer
430
+
431
+ # Returns the process id of the parent of this process. Returns untrustworthy
432
+ # value on Win32/64. Not available on all platforms.
433
+ #
434
+ # puts "I am #{Process.pid}"
435
+ # Process.fork { puts "Dad is #{Process.ppid}" }
436
+ #
437
+ # *produces:*
438
+ #
439
+ # I am 27417
440
+ # Dad is 27417
441
+ #
442
+ def self.ppid: () -> Integer
443
+
444
+ # Sets the process group ID of *pid* (0 indicates this process) to *integer*.
445
+ # Not available on all platforms.
446
+ #
447
+ def self.setpgid: (Integer pid, Integer arg0) -> Integer
448
+
449
+ # See Process.getpriority.
450
+ #
451
+ # Process.setpriority(Process::PRIO_USER, 0, 19) #=> 0
452
+ # Process.setpriority(Process::PRIO_PROCESS, 0, 19) #=> 0
453
+ # Process.getpriority(Process::PRIO_USER, 0) #=> 19
454
+ # Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19
455
+ #
456
+ def self.setpriority: (Integer kind, Integer arg0, Integer priority) -> Integer
457
+
458
+ # Sets the process title that appears on the ps(1) command. Not necessarily
459
+ # effective on all platforms. No exception will be raised regardless of the
460
+ # result, nor will NotImplementedError be raised even if the platform does not
461
+ # support the feature.
462
+ #
463
+ # Calling this method does not affect the value of $0.
464
+ #
465
+ # Process.setproctitle('myapp: worker #%d' % worker_id)
466
+ #
467
+ # This method first appeared in Ruby 2.1 to serve as a global variable free
468
+ # means to change the process title.
469
+ #
470
+ def self.setproctitle: (String arg0) -> String
471
+
472
+ # Sets the resource limit of the process. *cur_limit* means current (soft) limit
473
+ # and *max_limit* means maximum (hard) limit.
474
+ #
475
+ # If *max_limit* is not given, *cur_limit* is used.
476
+ #
477
+ # *resource* indicates the kind of resource to limit. It should be a symbol such
478
+ # as `:CORE`, a string such as `"CORE"` or a constant such as
479
+ # Process::RLIMIT_CORE. The available resources are OS dependent. Ruby may
480
+ # support following resources.
481
+ #
482
+ # AS
483
+ # : total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD but
484
+ # 4.4BSD-Lite)
485
+ # CORE
486
+ # : core size (bytes) (SUSv3)
487
+ # CPU
488
+ # : CPU time (seconds) (SUSv3)
489
+ # DATA
490
+ # : data segment (bytes) (SUSv3)
491
+ # FSIZE
492
+ # : file size (bytes) (SUSv3)
493
+ # MEMLOCK
494
+ # : total size for mlock(2) (bytes) (4.4BSD, GNU/Linux)
495
+ # MSGQUEUE
496
+ # : allocation for POSIX message queues (bytes) (GNU/Linux)
497
+ # NICE
498
+ # : ceiling on process's nice(2) value (number) (GNU/Linux)
499
+ # NOFILE
500
+ # : file descriptors (number) (SUSv3)
501
+ # NPROC
502
+ # : number of processes for the user (number) (4.4BSD, GNU/Linux)
503
+ # RSS
504
+ # : resident memory size (bytes) (4.2BSD, GNU/Linux)
505
+ # RTPRIO
506
+ # : ceiling on the process's real-time priority (number) (GNU/Linux)
507
+ # RTTIME
508
+ # : CPU time for real-time process (us) (GNU/Linux)
509
+ # SBSIZE
510
+ # : all socket buffers (bytes) (NetBSD, FreeBSD)
511
+ # SIGPENDING
512
+ # : number of queued signals allowed (signals) (GNU/Linux)
513
+ # STACK
514
+ # : stack size (bytes) (SUSv3)
515
+ #
516
+ #
517
+ # *cur_limit* and *max_limit* may be `:INFINITY`, `"INFINITY"` or
518
+ # Process::RLIM_INFINITY, which means that the resource is not limited. They may
519
+ # be Process::RLIM_SAVED_MAX, Process::RLIM_SAVED_CUR and corresponding symbols
520
+ # and strings too. See system setrlimit(2) manual for details.
521
+ #
522
+ # The following example raises the soft limit of core size to the hard limit to
523
+ # try to make core dump possible.
524
+ #
525
+ # Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1])
526
+ #
527
+ def self.setrlimit: (Symbol | String | Integer resource, Integer cur_limit, ?Integer max_limit) -> nil
528
+
529
+ # Establishes this process as a new session and process group leader, with no
530
+ # controlling tty. Returns the session id. Not available on all platforms.
531
+ #
532
+ # Process.setsid #=> 27422
533
+ #
534
+ def self.setsid: () -> Integer
535
+
536
+ # Returns a `Tms` structure (see Process::Tms) that contains user and system CPU
537
+ # times for this process, and also for children processes.
538
+ #
539
+ # t = Process.times
540
+ # [ t.utime, t.stime, t.cutime, t.cstime ] #=> [0.0, 0.02, 0.00, 0.00]
541
+ #
542
+ def self.times: () -> Process::Tms
543
+
544
+ # Returns the (real) user ID of this process.
545
+ #
546
+ # Process.uid #=> 501
547
+ #
548
+ def self.uid: () -> Integer
549
+
550
+ # Sets the (user) user ID for this process. Not available on all platforms.
551
+ #
552
+ def self.uid=: (Integer user) -> Integer
553
+
554
+ # Waits for a child process to exit, returns its process id, and sets `$?` to a
555
+ # Process::Status object containing information on that process. Which child it
556
+ # waits on depends on the value of *pid*:
557
+ #
558
+ # > 0
559
+ # : Waits for the child whose process ID equals *pid*.
560
+ #
561
+ # 0
562
+ # : Waits for any child whose process group ID equals that of the calling
563
+ # process.
564
+ #
565
+ # -1
566
+ # : Waits for any child process (the default if no *pid* is given).
567
+ #
568
+ # < -1
569
+ # : Waits for any child whose process group ID equals the absolute value of
570
+ # *pid*.
571
+ #
572
+ #
573
+ # The *flags* argument may be a logical or of the flag values Process::WNOHANG
574
+ # (do not block if no child available) or Process::WUNTRACED (return stopped
575
+ # children that haven't been reported). Not all flags are available on all
576
+ # platforms, but a flag value of zero will work on all platforms.
577
+ #
578
+ # Calling this method raises a SystemCallError if there are no child processes.
579
+ # Not available on all platforms.
580
+ #
581
+ # include Process
582
+ # fork { exit 99 } #=> 27429
583
+ # wait #=> 27429
584
+ # $?.exitstatus #=> 99
585
+ #
586
+ # pid = fork { sleep 3 } #=> 27440
587
+ # Time.now #=> 2008-03-08 19:56:16 +0900
588
+ # waitpid(pid, Process::WNOHANG) #=> nil
589
+ # Time.now #=> 2008-03-08 19:56:16 +0900
590
+ # waitpid(pid, 0) #=> 27440
591
+ # Time.now #=> 2008-03-08 19:56:19 +0900
592
+ #
593
+ def self.wait: (?Integer pid, ?Integer flags) -> Integer
594
+
595
+ # Waits for a child process to exit (see Process::waitpid for exact semantics)
596
+ # and returns an array containing the process id and the exit status (a
597
+ # Process::Status object) of that child. Raises a SystemCallError if there are
598
+ # no child processes.
599
+ #
600
+ # Process.fork { exit 99 } #=> 27437
601
+ # pid, status = Process.wait2
602
+ # pid #=> 27437
603
+ # status.exitstatus #=> 99
604
+ #
605
+ def self.wait2: (?Integer pid, ?Integer flags) -> [ Integer, Process::Status ]
606
+
607
+ # Waits for all children, returning an array of *pid*/*status* pairs (where
608
+ # *status* is a Process::Status object).
609
+ #
610
+ # fork { sleep 0.2; exit 2 } #=> 27432
611
+ # fork { sleep 0.1; exit 1 } #=> 27433
612
+ # fork { exit 0 } #=> 27434
613
+ # p Process.waitall
614
+ #
615
+ # *produces*:
616
+ #
617
+ # [[30982, #<Process::Status: pid 30982 exit 0>],
618
+ # [30979, #<Process::Status: pid 30979 exit 1>],
619
+ # [30976, #<Process::Status: pid 30976 exit 2>]]
620
+ #
621
+ def self.waitall: () -> ::Array[[ Integer, Process::Status ]]
622
+
623
+ # Waits for a child process to exit, returns its process id, and sets `$?` to a
624
+ # Process::Status object containing information on that process. Which child it
625
+ # waits on depends on the value of *pid*:
626
+ #
627
+ # > 0
628
+ # : Waits for the child whose process ID equals *pid*.
629
+ #
630
+ # 0
631
+ # : Waits for any child whose process group ID equals that of the calling
632
+ # process.
633
+ #
634
+ # -1
635
+ # : Waits for any child process (the default if no *pid* is given).
636
+ #
637
+ # < -1
638
+ # : Waits for any child whose process group ID equals the absolute value of
639
+ # *pid*.
640
+ #
641
+ #
642
+ # The *flags* argument may be a logical or of the flag values Process::WNOHANG
643
+ # (do not block if no child available) or Process::WUNTRACED (return stopped
644
+ # children that haven't been reported). Not all flags are available on all
645
+ # platforms, but a flag value of zero will work on all platforms.
646
+ #
647
+ # Calling this method raises a SystemCallError if there are no child processes.
648
+ # Not available on all platforms.
649
+ #
650
+ # include Process
651
+ # fork { exit 99 } #=> 27429
652
+ # wait #=> 27429
653
+ # $?.exitstatus #=> 99
654
+ #
655
+ # pid = fork { sleep 3 } #=> 27440
656
+ # Time.now #=> 2008-03-08 19:56:16 +0900
657
+ # waitpid(pid, Process::WNOHANG) #=> nil
658
+ # Time.now #=> 2008-03-08 19:56:16 +0900
659
+ # waitpid(pid, 0) #=> 27440
660
+ # Time.now #=> 2008-03-08 19:56:19 +0900
661
+ #
662
+ def self.waitpid: (?Integer pid, ?Integer flags) -> Integer
663
+
664
+ # Waits for a child process to exit (see Process::waitpid for exact semantics)
665
+ # and returns an array containing the process id and the exit status (a
666
+ # Process::Status object) of that child. Raises a SystemCallError if there are
667
+ # no child processes.
668
+ #
669
+ # Process.fork { exit 99 } #=> 27437
670
+ # pid, status = Process.wait2
671
+ # pid #=> 27437
672
+ # status.exitstatus #=> 99
673
+ #
674
+ def self.waitpid2: (?Integer pid, ?Integer flags) -> [ Integer, Process::Status ]
675
+ end
676
+
677
+ # see Process.clock_gettime
678
+ #
679
+ #
680
+ Process::CLOCK_BOOTTIME: Integer
681
+
682
+ # see Process.clock_gettime
683
+ #
684
+ #
685
+ Process::CLOCK_BOOTTIME_ALARM: Integer
686
+
687
+ # see Process.clock_gettime
688
+ #
689
+ #
690
+ Process::CLOCK_MONOTONIC: Integer
691
+
692
+ # see Process.clock_gettime
693
+ #
694
+ #
695
+ Process::CLOCK_MONOTONIC_COARSE: Integer
696
+
697
+ # see Process.clock_gettime
698
+ #
699
+ #
700
+ Process::CLOCK_MONOTONIC_RAW: Integer
701
+
702
+ # see Process.clock_gettime
703
+ #
704
+ #
705
+ Process::CLOCK_PROCESS_CPUTIME_ID: Integer
706
+
707
+ # see Process.clock_gettime
708
+ #
709
+ #
710
+ Process::CLOCK_REALTIME: Integer
711
+
712
+ # see Process.clock_gettime
713
+ #
714
+ #
715
+ Process::CLOCK_REALTIME_ALARM: Integer
716
+
717
+ # see Process.clock_gettime
718
+ #
719
+ #
720
+ Process::CLOCK_REALTIME_COARSE: Integer
721
+
722
+ # see Process.clock_gettime
723
+ #
724
+ #
725
+ Process::CLOCK_THREAD_CPUTIME_ID: Integer
726
+
727
+ # see Process.setpriority
728
+ #
729
+ #
730
+ Process::PRIO_PGRP: Integer
731
+
732
+ # see Process.setpriority
733
+ #
734
+ #
735
+ Process::PRIO_PROCESS: Integer
736
+
737
+ # see Process.setpriority
738
+ #
739
+ #
740
+ Process::PRIO_USER: Integer
741
+
742
+ # Maximum size of the process's virtual memory (address space) in bytes.
743
+ #
744
+ # see the system getrlimit(2) manual for details.
745
+ #
746
+ Process::RLIMIT_AS: Integer
747
+
748
+ # Maximum size of the core file.
749
+ #
750
+ # see the system getrlimit(2) manual for details.
751
+ #
752
+ Process::RLIMIT_CORE: Integer
753
+
754
+ # CPU time limit in seconds.
755
+ #
756
+ # see the system getrlimit(2) manual for details.
757
+ #
758
+ Process::RLIMIT_CPU: Integer
759
+
760
+ # Maximum size of the process's data segment.
761
+ #
762
+ # see the system getrlimit(2) manual for details.
763
+ #
764
+ Process::RLIMIT_DATA: Integer
765
+
766
+ # Maximum size of files that the process may create.
767
+ #
768
+ # see the system getrlimit(2) manual for details.
769
+ #
770
+ Process::RLIMIT_FSIZE: Integer
771
+
772
+ # Maximum number of bytes of memory that may be locked into RAM.
773
+ #
774
+ # see the system getrlimit(2) manual for details.
775
+ #
776
+ Process::RLIMIT_MEMLOCK: Integer
777
+
778
+ # Specifies the limit on the number of bytes that can be allocated for POSIX
779
+ # message queues for the real user ID of the calling process.
780
+ #
781
+ # see the system getrlimit(2) manual for details.
782
+ #
783
+ Process::RLIMIT_MSGQUEUE: Integer
784
+
785
+ # Specifies a ceiling to which the process's nice value can be raised.
786
+ #
787
+ # see the system getrlimit(2) manual for details.
788
+ #
789
+ Process::RLIMIT_NICE: Integer
790
+
791
+ # Specifies a value one greater than the maximum file descriptor number that can
792
+ # be opened by this process.
793
+ #
794
+ # see the system getrlimit(2) manual for details.
795
+ #
796
+ Process::RLIMIT_NOFILE: Integer
797
+
798
+ # The maximum number of processes that can be created for the real user ID of
799
+ # the calling process.
800
+ #
801
+ # see the system getrlimit(2) manual for details.
802
+ #
803
+ Process::RLIMIT_NPROC: Integer
804
+
805
+ # Specifies the limit (in pages) of the process's resident set.
806
+ #
807
+ # see the system getrlimit(2) manual for details.
808
+ #
809
+ Process::RLIMIT_RSS: Integer
810
+
811
+ # Specifies a ceiling on the real-time priority that may be set for this
812
+ # process.
813
+ #
814
+ # see the system getrlimit(2) manual for details.
815
+ #
816
+ Process::RLIMIT_RTPRIO: Integer
817
+
818
+ # Specifies limit on CPU time this process scheduled under a real-time
819
+ # scheduling policy can consume.
820
+ #
821
+ # see the system getrlimit(2) manual for details.
822
+ #
823
+ Process::RLIMIT_RTTIME: Integer
824
+
825
+ # Specifies a limit on the number of signals that may be queued for the real
826
+ # user ID of the calling process.
827
+ #
828
+ # see the system getrlimit(2) manual for details.
829
+ #
830
+ Process::RLIMIT_SIGPENDING: Integer
831
+
832
+ # Maximum size of the stack, in bytes.
833
+ #
834
+ # see the system getrlimit(2) manual for details.
835
+ #
836
+ Process::RLIMIT_STACK: Integer
837
+
838
+ # see Process.setrlimit
839
+ #
840
+ #
841
+ Process::RLIM_INFINITY: Integer
842
+
843
+ # see Process.setrlimit
844
+ #
845
+ #
846
+ Process::RLIM_SAVED_CUR: Integer
847
+
848
+ # see Process.setrlimit
849
+ #
850
+ #
851
+ Process::RLIM_SAVED_MAX: Integer
852
+
853
+ # see Process.wait
854
+ #
855
+ #
856
+ Process::WNOHANG: Integer
857
+
858
+ # see Process.wait
859
+ #
860
+ #
861
+ Process::WUNTRACED: Integer
862
+
863
+ # The Process::GID module contains a collection of module functions which can be
864
+ # used to portably get, set, and switch the current process's real, effective,
865
+ # and saved group IDs.
866
+ #
867
+ module Process::GID
868
+ # Change the current process's real and effective group ID to that specified by
869
+ # *group*. Returns the new group ID. Not available on all platforms.
870
+ #
871
+ # [Process.gid, Process.egid] #=> [0, 0]
872
+ # Process::GID.change_privilege(33) #=> 33
873
+ # [Process.gid, Process.egid] #=> [33, 33]
874
+ #
875
+ def self.change_privilege: (Integer group) -> Integer
876
+
877
+ # Returns the effective group ID for this process. Not available on all
878
+ # platforms.
879
+ #
880
+ # Process.egid #=> 500
881
+ #
882
+ def self.eid: () -> Integer
883
+
884
+ # Get the group ID by the *name*. If the group is not found, `ArgumentError`
885
+ # will be raised.
886
+ #
887
+ # Process::GID.from_name("wheel") #=> 0
888
+ # Process::GID.from_name("nosuchgroup") #=> can't find group for nosuchgroup (ArgumentError)
889
+ #
890
+ def self.from_name: (String name) -> Integer
891
+
892
+ # Set the effective group ID, and if possible, the saved group ID of the process
893
+ # to the given *group*. Returns the new effective group ID. Not available on all
894
+ # platforms.
895
+ #
896
+ # [Process.gid, Process.egid] #=> [0, 0]
897
+ # Process::GID.grant_privilege(31) #=> 33
898
+ # [Process.gid, Process.egid] #=> [0, 33]
899
+ #
900
+ def self.grant_privilege: (Integer group) -> Integer
901
+
902
+ # Exchange real and effective group IDs and return the new effective group ID.
903
+ # Not available on all platforms.
904
+ #
905
+ # [Process.gid, Process.egid] #=> [0, 33]
906
+ # Process::GID.re_exchange #=> 0
907
+ # [Process.gid, Process.egid] #=> [33, 0]
908
+ #
909
+ def self.re_exchange: () -> Integer
910
+
911
+ # Returns `true` if the real and effective group IDs of a process may be
912
+ # exchanged on the current platform.
913
+ #
914
+ def self.re_exchangeable?: () -> bool
915
+
916
+ # Returns the (real) group ID for this process.
917
+ #
918
+ # Process.gid #=> 500
919
+ #
920
+ def self.rid: () -> Integer
921
+
922
+ # Returns `true` if the current platform has saved group ID functionality.
923
+ #
924
+ def self.sid_available?: () -> bool
925
+
926
+ # Switch the effective and real group IDs of the current process. If a *block*
927
+ # is given, the group IDs will be switched back after the block is executed.
928
+ # Returns the new effective group ID if called without a block, and the return
929
+ # value of the block if one is given.
930
+ #
931
+ def self.switch: () -> Integer
932
+ | [T] () { () -> T } -> T
933
+
934
+ def self.eid=: (Integer group) -> Integer
935
+ end
936
+
937
+ # Process::Status encapsulates the information on the status of a running or
938
+ # terminated system process. The built-in variable `$?` is either `nil` or a
939
+ # Process::Status object.
940
+ #
941
+ # fork { exit 99 } #=> 26557
942
+ # Process.wait #=> 26557
943
+ # $?.class #=> Process::Status
944
+ # $?.to_i #=> 25344
945
+ # $? >> 8 #=> 99
946
+ # $?.stopped? #=> false
947
+ # $?.exited? #=> true
948
+ # $?.exitstatus #=> 99
949
+ #
950
+ # Posix systems record information on processes using a 16-bit integer. The
951
+ # lower bits record the process status (stopped, exited, signaled) and the upper
952
+ # bits possibly contain additional information (for example the program's return
953
+ # code in the case of exited processes). Pre Ruby 1.8, these bits were exposed
954
+ # directly to the Ruby program. Ruby now encapsulates these in a Process::Status
955
+ # object. To maximize compatibility, however, these objects retain a
956
+ # bit-oriented interface. In the descriptions that follow, when we talk about
957
+ # the integer value of *stat*, we're referring to this 16 bit value.
958
+ #
959
+ class Process::Status < Object
960
+ # Logical AND of the bits in *stat* with *num*.
961
+ #
962
+ # fork { exit 0x37 }
963
+ # Process.wait
964
+ # sprintf('%04x', $?.to_i) #=> "3700"
965
+ # sprintf('%04x', $? & 0x1e00) #=> "1600"
966
+ #
967
+ def &: (Integer num) -> Integer
968
+
969
+ # Returns `true` if the integer value of *stat* equals *other*.
970
+ #
971
+ def ==: (untyped other) -> bool
972
+
973
+ # Shift the bits in *stat* right *num* places.
974
+ #
975
+ # fork { exit 99 } #=> 26563
976
+ # Process.wait #=> 26563
977
+ # $?.to_i #=> 25344
978
+ # $? >> 8 #=> 99
979
+ #
980
+ def >>: (Integer num) -> Integer
981
+
982
+ # Returns `true` if *stat* generated a coredump when it terminated. Not
983
+ # available on all platforms.
984
+ #
985
+ def coredump?: () -> bool
986
+
987
+ # Returns `true` if *stat* exited normally (for example using an `exit()` call
988
+ # or finishing the program).
989
+ #
990
+ def exited?: () -> bool
991
+
992
+ # Returns the least significant eight bits of the return code of *stat*. Only
993
+ # available if #exited? is `true`.
994
+ #
995
+ # fork { } #=> 26572
996
+ # Process.wait #=> 26572
997
+ # $?.exited? #=> true
998
+ # $?.exitstatus #=> 0
999
+ #
1000
+ # fork { exit 99 } #=> 26573
1001
+ # Process.wait #=> 26573
1002
+ # $?.exited? #=> true
1003
+ # $?.exitstatus #=> 99
1004
+ #
1005
+ def exitstatus: () -> Integer?
1006
+
1007
+ # Override the inspection method.
1008
+ #
1009
+ # system("false")
1010
+ # p $?.inspect #=> "#<Process::Status: pid 12861 exit 1>"
1011
+ #
1012
+ def inspect: () -> String
1013
+
1014
+ # Returns the process ID that this status object represents.
1015
+ #
1016
+ # fork { exit } #=> 26569
1017
+ # Process.wait #=> 26569
1018
+ # $?.pid #=> 26569
1019
+ #
1020
+ def pid: () -> Integer
1021
+
1022
+ # Returns `true` if *stat* terminated because of an uncaught signal.
1023
+ #
1024
+ def signaled?: () -> bool
1025
+
1026
+ # Returns `true` if this process is stopped. This is only returned if the
1027
+ # corresponding #wait call had the Process::WUNTRACED flag set.
1028
+ #
1029
+ def stopped?: () -> bool
1030
+
1031
+ # Returns the number of the signal that caused *stat* to stop (or `nil` if self
1032
+ # is not stopped).
1033
+ #
1034
+ def stopsig: () -> Integer?
1035
+
1036
+ # Returns `true` if *stat* is successful, `false` if not. Returns `nil` if
1037
+ # #exited? is not `true`.
1038
+ #
1039
+ def success?: () -> bool
1040
+
1041
+ # Returns the number of the signal that caused *stat* to terminate (or `nil` if
1042
+ # self was not terminated by an uncaught signal).
1043
+ #
1044
+ def termsig: () -> Integer?
1045
+
1046
+ # Returns the bits in *stat* as a Integer. Poking around in these bits is
1047
+ # platform dependent.
1048
+ #
1049
+ # fork { exit 0xab } #=> 26566
1050
+ # Process.wait #=> 26566
1051
+ # sprintf('%04x', $?.to_i) #=> "ab00"
1052
+ #
1053
+ def to_i: () -> Integer
1054
+
1055
+ # Show pid and exit status as a string.
1056
+ #
1057
+ # system("false")
1058
+ # p $?.to_s #=> "pid 12766 exit 1"
1059
+ #
1060
+ def to_s: () -> String
1061
+ end
1062
+
1063
+ # The Process::Sys module contains UID and GID functions which provide direct
1064
+ # bindings to the system calls of the same names instead of the more-portable
1065
+ # versions of the same functionality found in the Process, Process::UID, and
1066
+ # Process::GID modules.
1067
+ #
1068
+ module Process::Sys
1069
+ # Returns the effective user ID for this process.
1070
+ #
1071
+ # Process.euid #=> 501
1072
+ #
1073
+ def self.geteuid: () -> Integer
1074
+
1075
+ # Returns the (real) group ID for this process.
1076
+ #
1077
+ # Process.gid #=> 500
1078
+ #
1079
+ def self.getgid: () -> Integer
1080
+
1081
+ # Returns the (real) user ID of this process.
1082
+ #
1083
+ # Process.uid #=> 501
1084
+ #
1085
+ def self.getuid: () -> Integer
1086
+
1087
+ # Returns `true` if the process was created as a result of an execve(2) system
1088
+ # call which had either of the setuid or setgid bits set (and extra privileges
1089
+ # were given as a result) or if it has changed any of its real, effective or
1090
+ # saved user or group IDs since it began execution.
1091
+ #
1092
+ def self.issetugid: () -> bool
1093
+
1094
+ # Set the effective group ID of the calling process to *group*. Not available
1095
+ # on all platforms.
1096
+ #
1097
+ def self.setegid: (Integer group) -> nil
1098
+
1099
+ # Set the effective user ID of the calling process to *user*. Not available on
1100
+ # all platforms.
1101
+ #
1102
+ def self.seteuid: (Integer user) -> nil
1103
+
1104
+ # Set the group ID of the current process to *group*. Not available on all
1105
+ # platforms.
1106
+ #
1107
+ def self.setgid: (Integer group) -> nil
1108
+
1109
+ # Sets the (group) real and/or effective group IDs of the current process to
1110
+ # *rid* and *eid*, respectively. A value of `-1` for either means to leave that
1111
+ # ID unchanged. Not available on all platforms.
1112
+ #
1113
+ def self.setregid: (Integer rid, Integer eid) -> nil
1114
+
1115
+ # Sets the (group) real, effective, and saved user IDs of the current process to
1116
+ # *rid*, *eid*, and *sid* respectively. A value of `-1` for any value means to
1117
+ # leave that ID unchanged. Not available on all platforms.
1118
+ #
1119
+ def self.setresgid: (Integer rid, Integer eid, Integer sid) -> nil
1120
+
1121
+ # Sets the (user) real, effective, and saved user IDs of the current process to
1122
+ # *rid*, *eid*, and *sid* respectively. A value of `-1` for any value means to
1123
+ # leave that ID unchanged. Not available on all platforms.
1124
+ #
1125
+ def self.setresuid: (Integer rid, Integer eid, Integer sid) -> nil
1126
+
1127
+ # Sets the (user) real and/or effective user IDs of the current process to *rid*
1128
+ # and *eid*, respectively. A value of `-1` for either means to leave that ID
1129
+ # unchanged. Not available on all platforms.
1130
+ #
1131
+ def self.setreuid: (Integer rid, Integer eid) -> nil
1132
+
1133
+ # Set the real group ID of the calling process to *group*. Not available on all
1134
+ # platforms.
1135
+ #
1136
+ def self.setrgid: (Integer group) -> nil
1137
+
1138
+ # Set the real user ID of the calling process to *user*. Not available on all
1139
+ # platforms.
1140
+ #
1141
+ def self.setruid: (Integer user) -> nil
1142
+
1143
+ # Set the user ID of the current process to *user*. Not available on all
1144
+ # platforms.
1145
+ #
1146
+ def self.setuid: (Integer user) -> nil
1147
+ end
1148
+
1149
+ # The Process::UID module contains a collection of module functions which can be
1150
+ # used to portably get, set, and switch the current process's real, effective,
1151
+ # and saved user IDs.
1152
+ #
1153
+ module Process::UID
1154
+ # Change the current process's real and effective user ID to that specified by
1155
+ # *user*. Returns the new user ID. Not available on all platforms.
1156
+ #
1157
+ # [Process.uid, Process.euid] #=> [0, 0]
1158
+ # Process::UID.change_privilege(31) #=> 31
1159
+ # [Process.uid, Process.euid] #=> [31, 31]
1160
+ #
1161
+ def self.change_privilege: (Integer user) -> Integer
1162
+
1163
+ # Returns the effective user ID for this process.
1164
+ #
1165
+ # Process.euid #=> 501
1166
+ #
1167
+ def self.eid: () -> Integer
1168
+
1169
+ # Get the user ID by the *name*. If the user is not found, `ArgumentError` will
1170
+ # be raised.
1171
+ #
1172
+ # Process::UID.from_name("root") #=> 0
1173
+ # Process::UID.from_name("nosuchuser") #=> can't find user for nosuchuser (ArgumentError)
1174
+ #
1175
+ def self.from_name: (String name) -> Integer
1176
+
1177
+ # Set the effective user ID, and if possible, the saved user ID of the process
1178
+ # to the given *user*. Returns the new effective user ID. Not available on all
1179
+ # platforms.
1180
+ #
1181
+ # [Process.uid, Process.euid] #=> [0, 0]
1182
+ # Process::UID.grant_privilege(31) #=> 31
1183
+ # [Process.uid, Process.euid] #=> [0, 31]
1184
+ #
1185
+ def self.grant_privilege: (Integer user) -> Integer
1186
+
1187
+ # Exchange real and effective user IDs and return the new effective user ID. Not
1188
+ # available on all platforms.
1189
+ #
1190
+ # [Process.uid, Process.euid] #=> [0, 31]
1191
+ # Process::UID.re_exchange #=> 0
1192
+ # [Process.uid, Process.euid] #=> [31, 0]
1193
+ #
1194
+ def self.re_exchange: () -> Integer
1195
+
1196
+ # Returns `true` if the real and effective user IDs of a process may be
1197
+ # exchanged on the current platform.
1198
+ #
1199
+ def self.re_exchangeable?: () -> bool
1200
+
1201
+ # Returns the (real) user ID of this process.
1202
+ #
1203
+ # Process.uid #=> 501
1204
+ #
1205
+ def self.rid: () -> Integer
1206
+
1207
+ # Returns `true` if the current platform has saved user ID functionality.
1208
+ #
1209
+ def self.sid_available?: () -> bool
1210
+
1211
+ # Switch the effective and real user IDs of the current process. If a *block* is
1212
+ # given, the user IDs will be switched back after the block is executed. Returns
1213
+ # the new effective user ID if called without a block, and the return value of
1214
+ # the block if one is given.
1215
+ #
1216
+ def self.switch: () -> Integer
1217
+ | [T] () { () -> T } -> T
1218
+
1219
+ def self.eid=: (Integer user) -> Integer
1220
+ end
1221
+
1222
+ class Process::Tms < Struct[Float]
1223
+ end
1224
+
1225
+ class Process::Waiter < Thread
1226
+ def pid: () -> Integer
1227
+ end