Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Processモジュール > wait
wait(pid = -1, flags = 0) -> Integer | nil
[permalink][rdoc]wait2(pid = -1, flags = 0) -> [Integer, Process::Status] | nil
waitpid(pid = -1, flags = 0) -> Integer | nil
waitpid2(pid = -1, flags = 0) -> [Integer, Process::Status] | nil
pid で指定される特定の子プロセスの終了を待ち、そのプロセスが終了した時に pid を返します。 wait2, waitpid2 は子プロセスの pid と終了ステータスを表す Process::Status オブジェクトの配列を返します。ノンブロッキングモードで子プロセスがまだ終了していない時には nil を返します。
$? に終了した子プロセスの Process::Status オブジェクトがセットされます。
pid = fork { sleep 1 }
Process.wait2 # => [70024, #<Process::Status: pid 70024 exit 0>]
[SEE_ALSO] wait(2), waitpid(2)