+ if timeout.is_a?(Fixnum)
+ # wait for the specified timeout
+ sleep timeout
+ else
+ # sleep while the agent thread is still alive
+ while(thread.alive?)
+ sleep 0.1
+ end
+ end
+
+ # 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