class MultiDaemons::Pid

Constants

KILL_TIMEOUT

Public Class Methods

default_timeout() click to toggle source
# File lib/multi_daemons/pid.rb, line 50
def self.default_timeout
  KILL_TIMEOUT
end
force_kill(pids, timeout = KILL_TIMEOUT) click to toggle source
# File lib/multi_daemons/pid.rb, line 18
def self.force_kill(pids, timeout = KILL_TIMEOUT)
  Timeout.timeout(force_kill_timeout(timeout), Timeout::Error) do
    pids.each do |pid|
      sleep(0.5) while Pid.running?(pid)
    end
  end
  true
rescue Timeout::Error
  Log.log 'Force stopping processes'
  pids.each do |pid|
    begin
      Process.kill('KILL', pid)
    rescue Errno::ESRCH
    end
  end

  begin
    Timeout.timeout(default_timeout, Timeout::Error) do
      pids.each do |pid|
        sleep 1 while Pid.running?(pid)
      end
    end
  rescue Timeout::Error
    Log.log 'Can not stop processes'
    return false
  end
end
force_kill_timeout(timeout) click to toggle source
# File lib/multi_daemons/pid.rb, line 46
def self.force_kill_timeout(timeout)
  timeout || KILL_TIMEOUT
end
running?(pid) click to toggle source
# File lib/multi_daemons/pid.rb, line 5
def self.running?(pid)
  return false unless pid

  begin
    Process.kill(0, pid)
    return true
  rescue Errno::ESRCH
    return false
  rescue Exception
    return true
  end
end