Method: LitmusPaper::Metric::Script#kill_and_reap_script

Defined in:
lib/litmus_paper/metric/script.rb

#kill_and_reap_script(pid) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/litmus_paper/metric/script.rb', line 45

def kill_and_reap_script(pid)
  Process.kill(9, pid)
  stop_time = Time.now + 2
  while Time.now < stop_time
    if Process.waitpid(pid, Process::WNOHANG)
      LitmusPaper.logger.info("Reaped PID #{pid}")
      return
    else
      sleep 0.1
    end
  end
  LitmusPaper.logger.error("Unable to reap PID #{pid}")
rescue Errno::ESRCH
  LitmusPaper.logger.info("Attempted to kill non-existent PID #{pid} (ESRCH)")
rescue Errno::ECHILD
  LitmusPaper.logger.info("Attempted to reap PID #{pid} but it has already been reaped (ECHILD)")
end