Class: Stalin::Killer
- Inherits:
-
Object
- Object
- Stalin::Killer
- Defined in:
- lib/stalin/killer.rb
Overview
Kill a process by sending SIGQUIT several times, then SIGTERM, and finally SIGKILL.
Constant Summary collapse
- MAX_GRACEFUL =
Number of cumulative shutdown tries before we escalate to abrupt-shutdown
10
- MAX_ABRUPT =
Number of cumulative shutdown tries before we escalate to untrappable SIGKILL
15
Instance Method Summary collapse
-
#initialize(pid, graceful, abrupt) ⇒ Killer
constructor
A new instance of Killer.
-
#kill ⇒ Symbol
Try to kill the target process by sending it a shutdown signal.
Constructor Details
#initialize(pid, graceful, abrupt) ⇒ Killer
Returns a new instance of Killer.
10 11 12 13 14 15 |
# File 'lib/stalin/killer.rb', line 10 def initialize(pid, graceful, abrupt) @pid = pid @graceful = graceful @abrupt = abrupt @tries = 0 end |
Instance Method Details
#kill ⇒ Symbol
Try to kill the target process by sending it a shutdown signal.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stalin/killer.rb', line 20 def kill case @tries when (0...MAX_GRACEFUL) sig = @graceful when (MAX_GRACEFUL...MAX_ABRUPT) sig = @abrupt else sig = :KILL end @tries += 1 Process.kill(sig, @pid) sig end |