class Foreman::Engine

def check_for_termination

def check_for_termination
  # Check if any of the children have died off
  pid, status = begin
    Process.wait2(-1, Process::WNOHANG)
  rescue Errno::ECHILD
    return nil
  end
  # record the exit status
  @exitstatus ||= status.exitstatus if status
  # If no childred have died, nothing to do here
  return nil unless pid
  # Log the information about the process that exited
  output_with_mutex name_for(pid), termination_message_for(status)
  # Delete it from the list of running processes and return its pid
  @running.delete(pid)
  return pid
end