rbs 3.3.2 → 3.4.0.pre.1

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