End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Process::Status.wait
VALUE
rb_process_status_waitv(int argc, VALUE *argv, VALUE _)
{
rb_check_arity(argc, 0, 2);
rb_pid_t pid = -1;
int flags = 0;
if (argc >= 1) {
pid = NUM2PIDT(argv[0]);
}
if (argc >= 2) {
flags = RB_NUM2INT(argv[1]);
}
return rb_process_status_wait(pid, flags);
}
Waits for a child process to exit and returns a Process::Status object containing information on that process. Which child it waits on depends on the value of pid:
- > 0
-
Waits for the child whose process ID equals pid.
- 0
-
Waits for any child whose process group ID equals that of the calling process.
- -1
-
Waits for any child process (the default if no pid is given).
- < -1
-
Waits for any child whose process group ID equals the absolute value of pid.
The flags argument may be a logical or of the flag values Process::WNOHANG (do not block if no child available) or Process::WUNTRACED (return stopped children that haven’t been reported). Not all flags are available on all platforms, but a flag value of zero will work on all platforms.
Returns nil if there are no child processes. Not available on all platforms.
May invoke the scheduler hook process_wait.
fork { exit 99 } #=> 27429 Process::Status.wait #=> pid 27429 exit 99 $? #=> nil pid = fork { sleep 3 } #=> 27440 Time.now #=> 2008-03-08 19:56:16 +0900 Process::Status.wait(pid, Process::WNOHANG) #=> nil Time.now #=> 2008-03-08 19:56:16 +0900 Process::Status.wait(pid, 0) #=> pid 27440 exit 99 Time.now #=> 2008-03-08 19:56:19 +0900
This is an EXPERIMENTAL FEATURE.