title: Waiting for Ruby child pid to exit
body: <p>I'm trying to fork a sub-process, wait for it to finish, if it doesn't finish within a certain amount of time, kill it.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>servers.each do |server|
      pid = fork do
          puts "Forking #{server}."
          output = "doing stuff here"
          puts output
      end
  
      Process.wait
      puts "#{server} child exited, pid = #{pid}"
  end
  </code></pre>
  
  <p>Somewhere after/around Process.wait, I would like some sort of utility to wait 20 seconds, and if the process is still out there, I'd like to kill it and mark output as "ERROR."</p>
  
  <p>I'm new to fork/exec. My code actually forking works, but I just don't know how to approach the waiting / killing aspect of it.</p>