For child processes, other solutions, such as sending a signal, will not behave as expected: they will indicate that the process is still running when it really exited.
You can use Process.waitpid if you want to check the process that you spawned on your own. The call will not be blocked if you use the Process::WNOHANG , and nil will be returned until the child process terminates.
Example:
pid = Process.spawn('sleep 5') Process.waitpid(pid, Process::WNOHANG) # => nil sleep 5 Process.waitpid(pid, Process::WNOHANG) # => pid
If pid does not belong to the child process, an exception will be thrown ( Errno::ECHILD: No child processes ).
The same goes for Process.waitpid2 .
balu Jan 17 '13 at 15:00 2013-01-17 15:00
source share