Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Process.waitpid2

Process.wait2(pid=-1, flags=0) → [pid, status]
Process.waitpid2(pid=-1, flags=0) → [pid, status]

Waits for a child process to exit (see Process::waitpid for exact semantics) and returns an array containing the process id and the exit status (a Process::Status object) of that child. Raises a SystemCallError if there are no child processes.

Example
Process.fork { exit 99 }   #=> 27437
pid, status = Process.wait2
pid                        #=> 27437
status.exitstatus          #=> 99
See also .waitpid .waitall also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1