module Mixlib::ShellOut::Unix

def reap_errant_child

def reap_errant_child
  return if attempt_reap
  @terminate_reason = "Command execeded allowed execution time, killed by TERM signal."
  logger.error("Command execeded allowed execution time, sending TERM") if logger
  Process.kill(:TERM, @child_pid)
  sleep 3
  return if attempt_reap
  @terminate_reason = "Command execeded allowed execution time, did not respond to TERM. Killed by KILL signal."
  logger.error("Command did not exit from TERM, sending KILL") if logger
  Process.kill(:KILL, @child_pid)
  reap
  # Should not hit this but it's possible if something is calling waitall
  # in a separate thread.
rescue Errno::ESRCH
  nil
end