+ # if the process is still running
+ if (Process.kill(0, cid))
+ # and a timeout was specified
+ if timeout
+ if Util.windows?
+ Process.kill('KILL', cid)
+ else
+ # Kill the process
+ Process.kill('TERM', cid)
+ sleep 2
+ Process.kill('KILL', cid) if (Process.kill(0, cid))
+ end
+ end
+ # only wait if the parent thread is dead
+ Process.waitpid(cid) unless thread.alive?
+ end