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.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -5
- data/.github/workflows/ruby.yml +7 -8
- data/.github/workflows/typecheck.yml +37 -0
- data/CHANGELOG.md +50 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/Steepfile +2 -2
- data/core/array.rbs +19 -49
- data/core/basic_object.rbs +2 -2
- data/core/comparable.rbs +17 -8
- data/core/complex.rbs +82 -43
- data/core/data.rbs +2 -4
- data/core/dir.rbs +635 -295
- data/core/enumerable.rbs +11 -18
- data/core/enumerator.rbs +37 -31
- data/core/errors.rbs +4 -0
- data/core/false_class.rbs +34 -15
- data/core/fiber.rbs +23 -0
- data/core/file.rbs +329 -120
- data/core/float.rbs +17 -32
- data/core/gc.rbs +17 -11
- data/core/hash.rbs +22 -44
- data/core/integer.rbs +82 -113
- data/core/io/buffer.rbs +90 -47
- data/core/io.rbs +39 -116
- data/core/kernel.rbs +442 -489
- data/core/match_data.rbs +55 -56
- data/core/module.rbs +45 -1
- data/core/nil_class.rbs +98 -35
- data/core/numeric.rbs +22 -32
- data/core/object_space/weak_key_map.rbs +102 -0
- data/core/process.rbs +1242 -655
- data/core/ractor.rbs +139 -120
- data/core/range.rbs +100 -4
- data/core/rational.rbs +0 -4
- data/core/rbs/unnamed/argf.rbs +16 -8
- data/core/rbs/unnamed/env_class.rbs +0 -24
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +1149 -598
- data/core/ruby_vm.rbs +126 -12
- data/core/rubygems/platform.rbs +9 -0
- data/core/rubygems/rubygems.rbs +1 -1
- data/core/rubygems/version.rbs +5 -1
- data/core/set.rbs +20 -22
- data/core/signal.rbs +4 -4
- data/core/string.rbs +283 -230
- data/core/string_io.rbs +2 -14
- data/core/struct.rbs +404 -24
- data/core/symbol.rbs +1 -19
- data/core/thread.rbs +29 -12
- data/core/time.rbs +227 -104
- data/core/trace_point.rbs +2 -5
- data/core/true_class.rbs +54 -21
- data/core/warning.rbs +14 -11
- data/docs/data_and_struct.md +29 -0
- data/docs/syntax.md +3 -5
- data/docs/tools.md +1 -0
- data/ext/rbs_extension/lexer.c +643 -559
- data/ext/rbs_extension/lexer.re +5 -1
- data/ext/rbs_extension/parser.c +12 -3
- data/ext/rbs_extension/unescape.c +7 -47
- data/lib/rbs/cli/diff.rb +4 -1
- data/lib/rbs/cli/validate.rb +280 -0
- data/lib/rbs/cli.rb +2 -194
- data/lib/rbs/collection/config.rb +5 -6
- data/lib/rbs/collection/sources/git.rb +1 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/diff.rb +7 -4
- data/lib/rbs/errors.rb +11 -0
- data/lib/rbs/test/errors.rb +4 -1
- data/lib/rbs/test/guaranteed.rb +2 -3
- data/lib/rbs/test/type_check.rb +15 -10
- data/lib/rbs/test.rb +3 -3
- data/lib/rbs/types.rb +29 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +136 -0
- data/lib/rbs/unit_test/type_assertions.rb +341 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/cli/validate.rbs +43 -0
- data/sig/diff.rbs +3 -1
- data/sig/errors.rbs +8 -0
- data/sig/rbs.rbs +1 -1
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/types.rbs +6 -1
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +28 -0
- data/sig/unit_test/type_assertions.rbs +194 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/stdlib/base64/0/base64.rbs +307 -45
- data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
- data/stdlib/coverage/0/coverage.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +25 -55
- data/stdlib/date/0/date.rbs +1 -43
- data/stdlib/date/0/date_time.rbs +1 -13
- data/stdlib/delegate/0/delegator.rbs +186 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +98 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
- data/stdlib/erb/0/erb.rbs +2 -2
- data/stdlib/fileutils/0/fileutils.rbs +0 -19
- data/stdlib/io-console/0/io-console.rbs +12 -1
- data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
- data/stdlib/json/0/json.rbs +320 -81
- data/stdlib/logger/0/logger.rbs +9 -5
- data/stdlib/monitor/0/monitor.rbs +78 -0
- data/stdlib/net-http/0/net-http.rbs +1880 -543
- data/stdlib/objspace/0/objspace.rbs +19 -13
- data/stdlib/openssl/0/openssl.rbs +508 -127
- data/stdlib/optparse/0/optparse.rbs +25 -11
- data/stdlib/pathname/0/pathname.rbs +1 -1
- data/stdlib/pp/0/pp.rbs +2 -5
- data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
- data/stdlib/pstore/0/pstore.rbs +2 -4
- data/stdlib/rdoc/0/comment.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +4 -2
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/socket/0/unix_socket.rbs +2 -2
- data/stdlib/strscan/0/string_scanner.rbs +3 -2
- data/stdlib/tempfile/0/tempfile.rbs +1 -1
- data/stdlib/uri/0/common.rbs +245 -123
- metadata +23 -4
- data/lib/rbs/test/spy.rb +0 -6
data/core/process.rbs
CHANGED
@@ -1,18 +1,329 @@
|
|
1
1
|
# <!-- rdoc-file=process.c -->
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
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
|
362
|
+
# - Process.clock_getres(clock_id, unit = :float_second) -> number
|
52
363
|
# -->
|
53
|
-
# Returns
|
54
|
-
#
|
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
|
-
#
|
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
|
-
#
|
369
|
+
# See Process.clock_gettime for the values of `clock_id` and `unit`.
|
68
370
|
#
|
69
|
-
#
|
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
|
-
#
|
74
|
-
#
|
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
|
-
#
|
77
|
-
#
|
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
|
-
#
|
80
|
-
#
|
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
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
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
|
93
|
-
# -->
|
94
|
-
# Returns a time
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# `clock_id`
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
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
|
161
|
-
# CLOCK_THREAD_CPUTIME_ID are optional.
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
# :
|
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
|
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
|
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
|
245
|
-
# UTC
|
246
|
-
#
|
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()
|
256
|
-
# - Process.daemon(nochdir=nil,noclose=nil) -> 0
|
562
|
+
# - Process.daemon(nochdir = nil, noclose = nil) -> 0
|
257
563
|
# -->
|
258
|
-
#
|
259
|
-
# system daemon
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
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)
|
583
|
+
# - Process.detach(pid) -> thread
|
269
584
|
# -->
|
270
|
-
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
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
|
-
#
|
279
|
-
#
|
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
|
-
#
|
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
|
-
#
|
285
|
-
#
|
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
|
-
#
|
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
|
-
#
|
603
|
+
# 312716 Z
|
294
604
|
#
|
295
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
313
|
-
# - Process::GID.eid
|
314
|
-
# - Process::Sys.geteid
|
622
|
+
# - Process.egid -> integer
|
623
|
+
# - Process::GID.eid -> integer
|
624
|
+
# - Process::Sys.geteid -> integer
|
315
625
|
# -->
|
316
|
-
# Returns the effective group ID for
|
317
|
-
#
|
626
|
+
# Returns the effective group ID for the current process:
|
627
|
+
#
|
628
|
+
# Process.egid # => 500
|
318
629
|
#
|
319
|
-
#
|
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 =
|
636
|
+
# - Process.egid = new_egid -> new_egid
|
326
637
|
# -->
|
327
|
-
# Sets the effective group ID for
|
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
|
334
|
-
# - Process::UID.eid
|
335
|
-
# - Process::Sys.geteuid
|
646
|
+
# - Process.euid -> integer
|
647
|
+
# - Process::UID.eid -> integer
|
648
|
+
# - Process::Sys.geteuid -> integer
|
336
649
|
# -->
|
337
|
-
# Returns the effective user ID for
|
650
|
+
# Returns the effective user ID for the current process.
|
338
651
|
#
|
339
|
-
# Process.euid
|
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=
|
658
|
+
# - Process.euid = new_euid -> new_euid
|
346
659
|
# -->
|
347
|
-
# Sets the effective user ID for
|
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)
|
668
|
+
# - Process.getpgid(pid) -> integer
|
354
669
|
# -->
|
355
|
-
# Returns the process group ID for the given process
|
356
|
-
#
|
670
|
+
# Returns the process group ID for the given process ID +pid+:
|
671
|
+
#
|
672
|
+
# Process.getpgid(Process.ppid) # => 25527
|
357
673
|
#
|
358
|
-
#
|
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
|
680
|
+
# - Process.getpgrp -> integer
|
365
681
|
# -->
|
366
|
-
# Returns the process group ID for
|
682
|
+
# Returns the process group ID for the current process:
|
367
683
|
#
|
368
|
-
# Process.getpgid(0)
|
369
|
-
# Process.getpgrp
|
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,
|
691
|
+
# - Process.getpriority(kind, id) -> integer
|
376
692
|
# -->
|
377
|
-
#
|
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
|
-
#
|
385
|
-
#
|
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)
|
716
|
+
# - Process.getrlimit(resource) -> [cur_limit, max_limit]
|
392
717
|
# -->
|
393
|
-
#
|
394
|
-
#
|
718
|
+
# Returns a 2-element array of the current (soft) limit and maximum (hard) limit
|
719
|
+
# for the given `resource`.
|
395
720
|
#
|
396
|
-
#
|
397
|
-
#
|
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
|
-
#
|
401
|
-
# Process
|
402
|
-
#
|
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()
|
409
|
-
# - Process.getsid(pid) -> integer
|
739
|
+
# - Process.getsid(pid = nil) -> integer
|
410
740
|
# -->
|
411
|
-
# Returns the session ID
|
412
|
-
# process
|
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
|
-
#
|
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
|
423
|
-
# - Process::GID.rid
|
424
|
-
# - Process::Sys.getgid
|
754
|
+
# - Process.gid -> integer
|
755
|
+
# - Process::GID.rid -> integer
|
756
|
+
# - Process::Sys.getgid -> integer
|
425
757
|
# -->
|
426
|
-
# Returns the (real) group ID for
|
758
|
+
# Returns the (real) group ID for the current process:
|
427
759
|
#
|
428
|
-
# Process.gid
|
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=
|
766
|
+
# - Process.gid = new_gid -> new_gid
|
435
767
|
# -->
|
436
|
-
# Sets the group ID for
|
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
|
776
|
+
# - Process.groups -> array
|
443
777
|
# -->
|
444
|
-
#
|
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
|
781
|
+
# Process.groups # => [4, 24, 27, 30, 46, 122, 135, 136, 1000]
|
448
782
|
#
|
449
|
-
#
|
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
|
453
|
-
# * the
|
454
|
-
# * the
|
455
|
-
# * the
|
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
|
-
#
|
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=
|
799
|
+
# - Process.groups = new_groups -> new_groups
|
468
800
|
# -->
|
469
|
-
#
|
801
|
+
# Sets the supplemental group access list to the given array of group IDs.
|
470
802
|
#
|
471
|
-
# Process.groups
|
472
|
-
# Process.groups = [27, 6, 10, 11]
|
473
|
-
# Process.groups
|
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)
|
811
|
+
# - Process.initgroups(username, gid) -> array
|
480
812
|
# -->
|
481
|
-
#
|
482
|
-
#
|
483
|
-
#
|
484
|
-
#
|
485
|
-
#
|
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
|
488
|
-
# Process.initgroups(
|
489
|
-
# Process.groups
|
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,
|
832
|
+
# - Process.kill(signal, *ids) -> count
|
496
833
|
# -->
|
497
|
-
# Sends
|
498
|
-
#
|
499
|
-
#
|
500
|
-
#
|
501
|
-
#
|
502
|
-
#
|
503
|
-
#
|
504
|
-
#
|
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
|
-
#
|
508
|
-
#
|
884
|
+
# Signal.trap('HUP') { puts 'Ouch!'; exit }
|
885
|
+
# # ... do some work ...
|
509
886
|
# end
|
510
887
|
# # ...
|
511
|
-
# Process.kill(
|
888
|
+
# Process.kill('HUP', pid)
|
512
889
|
# Process.wait
|
513
890
|
#
|
514
|
-
#
|
891
|
+
# Output:
|
515
892
|
#
|
516
893
|
# Ouch!
|
517
894
|
#
|
518
|
-
#
|
519
|
-
#
|
520
|
-
#
|
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
|
-
#
|
523
|
-
#
|
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
|
909
|
+
# - Process.maxgroups -> integer
|
531
910
|
# -->
|
532
|
-
# Returns the maximum number of
|
533
|
-
# list
|
911
|
+
# Returns the maximum number of group IDs allowed in the supplemental group
|
912
|
+
# access list:
|
534
913
|
#
|
535
|
-
# Process.maxgroups
|
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=
|
920
|
+
# - Process.maxgroups = new_max -> new_max
|
542
921
|
# -->
|
543
|
-
# Sets the maximum number of
|
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
|
929
|
+
# - Process.pid -> integer
|
550
930
|
# -->
|
551
|
-
# Returns the process
|
931
|
+
# Returns the process ID of the current process:
|
552
932
|
#
|
553
|
-
# Process.pid
|
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
|
939
|
+
# - Process.ppid -> integer
|
560
940
|
# -->
|
561
|
-
# Returns the process
|
562
|
-
#
|
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
|
-
#
|
565
|
-
# Process.fork { puts "Dad is #{Process.ppid}" }
|
946
|
+
# Output:
|
566
947
|
#
|
567
|
-
#
|
948
|
+
# Pid is 271290.
|
949
|
+
# Parent pid is 271290.
|
568
950
|
#
|
569
|
-
#
|
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,
|
957
|
+
# - Process.setpgid(pid, pgid) -> 0
|
577
958
|
# -->
|
578
|
-
# Sets the process group ID
|
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)
|
967
|
+
# - Process.setpriority(kind, integer, priority) -> 0
|
586
968
|
# -->
|
587
969
|
# See Process.getpriority.
|
588
970
|
#
|
589
|
-
#
|
590
|
-
#
|
591
|
-
# Process.
|
592
|
-
# Process.
|
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)
|
617
|
-
#
|
618
|
-
#
|
619
|
-
#
|
620
|
-
#
|
621
|
-
#
|
622
|
-
#
|
623
|
-
#
|
624
|
-
#
|
625
|
-
#
|
626
|
-
#
|
627
|
-
#
|
628
|
-
#
|
629
|
-
#
|
630
|
-
#
|
631
|
-
#
|
632
|
-
#
|
633
|
-
#
|
634
|
-
#
|
635
|
-
#
|
636
|
-
#
|
637
|
-
#
|
638
|
-
#
|
639
|
-
#
|
640
|
-
#
|
641
|
-
#
|
642
|
-
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
#
|
646
|
-
#
|
647
|
-
#
|
648
|
-
#
|
649
|
-
#
|
650
|
-
#
|
651
|
-
#
|
652
|
-
#
|
653
|
-
#
|
654
|
-
#
|
655
|
-
#
|
656
|
-
#
|
657
|
-
#
|
658
|
-
#
|
659
|
-
#
|
660
|
-
#
|
661
|
-
#
|
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
|
1057
|
+
# - Process.setsid -> integer
|
681
1058
|
# -->
|
682
|
-
# Establishes
|
683
|
-
# controlling tty
|
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
|
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
|
1070
|
+
# - Process.times -> process_tms
|
692
1071
|
# -->
|
693
|
-
# Returns a
|
694
|
-
#
|
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
|
-
#
|
697
|
-
#
|
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
|
704
|
-
# - Process::UID.rid
|
705
|
-
# - Process::Sys.getuid
|
1084
|
+
# - Process.uid -> integer
|
1085
|
+
# - Process::UID.rid -> integer
|
1086
|
+
# - Process::Sys.getuid -> integer
|
706
1087
|
# -->
|
707
|
-
# Returns the (real) user ID of
|
1088
|
+
# Returns the (real) user ID of the current process.
|
708
1089
|
#
|
709
|
-
# Process.uid
|
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=
|
1096
|
+
# - Process.uid = new_uid -> new_uid
|
716
1097
|
# -->
|
717
|
-
# Sets the (user) user ID for
|
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()
|
724
|
-
#
|
725
|
-
#
|
726
|
-
#
|
727
|
-
#
|
728
|
-
#
|
729
|
-
#
|
730
|
-
#
|
731
|
-
#
|
732
|
-
#
|
733
|
-
#
|
734
|
-
#
|
735
|
-
#
|
736
|
-
#
|
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
|
-
#
|
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
|
771
|
-
# - Process.waitpid2(pid=-1, flags=0) -> [pid, status]
|
1245
|
+
# - Process.wait2(pid = -1, flags = 0) -> [pid, status]
|
772
1246
|
# -->
|
773
|
-
#
|
774
|
-
# and
|
775
|
-
#
|
776
|
-
#
|
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
|
-
#
|
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
|
1260
|
+
# - Process.waitall -> array
|
788
1261
|
# -->
|
789
|
-
# Waits for all children,
|
790
|
-
#
|
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
|
-
#
|
800
|
-
#
|
801
|
-
#
|
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()
|
808
|
-
#
|
809
|
-
#
|
810
|
-
#
|
811
|
-
#
|
812
|
-
#
|
813
|
-
#
|
814
|
-
#
|
815
|
-
#
|
816
|
-
#
|
817
|
-
#
|
818
|
-
#
|
819
|
-
#
|
820
|
-
#
|
821
|
-
#
|
822
|
-
#
|
823
|
-
#
|
824
|
-
#
|
825
|
-
#
|
826
|
-
#
|
827
|
-
#
|
828
|
-
#
|
829
|
-
#
|
830
|
-
#
|
831
|
-
#
|
832
|
-
#
|
833
|
-
#
|
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
|
-
#
|
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
|
855
|
-
# - Process.waitpid2(pid=-1, flags=0) -> [pid, status]
|
1412
|
+
# - Process.wait2(pid = -1, flags = 0) -> [pid, status]
|
856
1413
|
# -->
|
857
|
-
#
|
858
|
-
# and
|
859
|
-
#
|
860
|
-
#
|
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
|
-
#
|
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
|
1101
|
-
# - Process::GID.eid
|
1102
|
-
# - Process::Sys.geteid
|
1683
|
+
# - Process.egid -> integer
|
1684
|
+
# - Process::GID.eid -> integer
|
1685
|
+
# - Process::Sys.geteid -> integer
|
1103
1686
|
# -->
|
1104
|
-
# Returns the effective group ID for
|
1105
|
-
# platforms.
|
1687
|
+
# Returns the effective group ID for the current process:
|
1106
1688
|
#
|
1107
|
-
# Process.egid
|
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
|
1163
|
-
# - Process::GID.rid
|
1164
|
-
# - Process::Sys.getgid
|
1746
|
+
# - Process.gid -> integer
|
1747
|
+
# - Process::GID.rid -> integer
|
1748
|
+
# - Process::Sys.getgid -> integer
|
1165
1749
|
# -->
|
1166
|
-
# Returns the (real) group ID for
|
1750
|
+
# Returns the (real) group ID for the current process:
|
1167
1751
|
#
|
1168
|
-
# Process.gid
|
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
|
1198
|
-
#
|
1199
|
-
#
|
1200
|
-
#
|
1201
|
-
#
|
1202
|
-
#
|
1203
|
-
#
|
1204
|
-
#
|
1205
|
-
#
|
1206
|
-
#
|
1207
|
-
#
|
1208
|
-
#
|
1209
|
-
#
|
1210
|
-
#
|
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 &
|
1799
|
+
# - stat & mask -> integer
|
1223
1800
|
# -->
|
1224
|
-
#
|
1801
|
+
# This method is deprecated; use other attribute methods.
|
1225
1802
|
#
|
1226
|
-
#
|
1227
|
-
#
|
1228
|
-
#
|
1229
|
-
#
|
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
|
1816
|
+
# - stat == other -> true or false
|
1236
1817
|
# -->
|
1237
|
-
# Returns
|
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 >>
|
1829
|
+
# - stat >> places -> integer
|
1244
1830
|
# -->
|
1245
|
-
#
|
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
|
-
#
|
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
|
-
# -
|
1847
|
+
# - coredump? -> true or false
|
1257
1848
|
# -->
|
1258
|
-
# Returns `true` if
|
1259
|
-
#
|
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
|
-
# -
|
1858
|
+
# - exited? -> true or false
|
1266
1859
|
# -->
|
1267
|
-
# Returns `true` if
|
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
|
-
# -
|
1867
|
+
# - exitstatus -> integer or nil
|
1275
1868
|
# -->
|
1276
|
-
# Returns the least significant eight bits of the return code of
|
1277
|
-
#
|
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
|
-
#
|
1285
|
-
#
|
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
|
-
# -
|
1879
|
+
# - inspect -> string
|
1294
1880
|
# -->
|
1295
|
-
#
|
1881
|
+
# Returns a string representation of `self`:
|
1296
1882
|
#
|
1297
1883
|
# system("false")
|
1298
|
-
#
|
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
|
-
# -
|
1890
|
+
# - pid -> integer
|
1305
1891
|
# -->
|
1306
|
-
# Returns the process ID
|
1892
|
+
# Returns the process ID of the process:
|
1307
1893
|
#
|
1308
|
-
#
|
1309
|
-
#
|
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
|
-
# -
|
1901
|
+
# - signaled? -> true or false
|
1317
1902
|
# -->
|
1318
|
-
# Returns `true` if
|
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
|
-
# -
|
1910
|
+
# - stopped? -> true or false
|
1325
1911
|
# -->
|
1326
|
-
# Returns `true` if this process is stopped
|
1327
|
-
#
|
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
|
-
# -
|
1919
|
+
# - stopsig -> integer or nil
|
1334
1920
|
# -->
|
1335
|
-
# Returns the number of the signal that caused
|
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
|
-
# -
|
1928
|
+
# - success? -> true, false, or nil
|
1343
1929
|
# -->
|
1344
|
-
# Returns
|
1345
|
-
#
|
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
|
-
# -
|
1940
|
+
# - termsig -> integer or nil
|
1352
1941
|
# -->
|
1353
|
-
# Returns the number of the signal that caused
|
1354
|
-
#
|
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
|
-
# -
|
1949
|
+
# - to_i -> integer
|
1361
1950
|
# -->
|
1362
|
-
# Returns the
|
1363
|
-
# platform dependent.
|
1951
|
+
# Returns the system-dependent integer status of `self`:
|
1364
1952
|
#
|
1365
|
-
#
|
1366
|
-
#
|
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
|
-
# -
|
1960
|
+
# - to_s -> string
|
1374
1961
|
# -->
|
1375
|
-
#
|
1962
|
+
# Returns a string representation of `self`:
|
1376
1963
|
#
|
1377
|
-
#
|
1378
|
-
#
|
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
|
1393
|
-
# - Process::UID.eid
|
1394
|
-
# - Process::Sys.geteuid
|
1979
|
+
# - Process.euid -> integer
|
1980
|
+
# - Process::UID.eid -> integer
|
1981
|
+
# - Process::Sys.geteuid -> integer
|
1395
1982
|
# -->
|
1396
|
-
# Returns the effective user ID for
|
1983
|
+
# Returns the effective user ID for the current process.
|
1397
1984
|
#
|
1398
|
-
# Process.euid
|
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
|
1405
|
-
# - Process::GID.rid
|
1406
|
-
# - Process::Sys.getgid
|
1991
|
+
# - Process.gid -> integer
|
1992
|
+
# - Process::GID.rid -> integer
|
1993
|
+
# - Process::Sys.getgid -> integer
|
1407
1994
|
# -->
|
1408
|
-
# Returns the (real) group ID for
|
1995
|
+
# Returns the (real) group ID for the current process:
|
1409
1996
|
#
|
1410
|
-
# Process.gid
|
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
|
1417
|
-
# - Process::UID.rid
|
1418
|
-
# - Process::Sys.getuid
|
2003
|
+
# - Process.uid -> integer
|
2004
|
+
# - Process::UID.rid -> integer
|
2005
|
+
# - Process::Sys.getuid -> integer
|
1419
2006
|
# -->
|
1420
|
-
# Returns the (real) user ID of
|
2007
|
+
# Returns the (real) user ID of the current process.
|
1421
2008
|
#
|
1422
|
-
# Process.uid
|
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
|
1554
|
-
# - Process::UID.eid
|
1555
|
-
# - Process::Sys.geteuid
|
2140
|
+
# - Process.euid -> integer
|
2141
|
+
# - Process::UID.eid -> integer
|
2142
|
+
# - Process::Sys.geteuid -> integer
|
1556
2143
|
# -->
|
1557
|
-
# Returns the effective user ID for
|
2144
|
+
# Returns the effective user ID for the current process.
|
1558
2145
|
#
|
1559
|
-
# Process.euid
|
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
|
1615
|
-
# - Process::UID.rid
|
1616
|
-
# - Process::Sys.getuid
|
2201
|
+
# - Process.uid -> integer
|
2202
|
+
# - Process::UID.rid -> integer
|
2203
|
+
# - Process::Sys.getuid -> integer
|
1617
2204
|
# -->
|
1618
|
-
# Returns the (real) user ID of
|
2205
|
+
# Returns the (real) user ID of the current process.
|
1619
2206
|
#
|
1620
|
-
# Process.uid
|
2207
|
+
# Process.uid # => 1000
|
1621
2208
|
#
|
1622
2209
|
def self.rid: () -> Integer
|
1623
2210
|
|