Module: Process

Extended by:
Process
Included in:
Process
Defined in:
lib/stubby/process.rb

Instance Method Summary collapse

Instance Method Details

#running?(pid) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/stubby/process.rb', line 4

def running?(pid)
  !!(kill(0, pid))
rescue
  false
end

#shutdown(pid, timeout = 10, sig1 = "TERM", sig2 = "KILL") ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stubby/process.rb', line 10

def shutdown(pid, timeout=10, sig1="TERM", sig2="KILL")
  puts "Shutting down: #{pid}"

  kill(sig1, pid)

  Timeout::timeout(timeout) do
    sleep 1 and puts "." while running?(pid)
  end 
rescue Timeout::Error
  kill(sig2, pid)
end