Search code examples
ruby

Ruby: wait for any child process to finish


Is there a way to wait for any (not all!) child process to finish? I am writing a Rake task that spawns several child processes and I want to start an action as soon as the first child process is finished.


Solution

  • Just call

    Process.wait
    

    With no arguments. This waits for any child process to terminate (see docs)

    You can also wait for children of a specific process group - possibly useful if you need more control.