Class: Chukan::ZombieKiller
- Inherits:
-
Object
- Object
- Chukan::ZombieKiller
- Defined in:
- lib/chukan.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(pid) ⇒ ZombieKiller
constructor
A new instance of ZombieKiller.
- #killed ⇒ Object
Constructor Details
#initialize(pid) ⇒ ZombieKiller
296 297 298 |
# File 'lib/chukan.rb', line 296 def initialize(pid) @pid = pid end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
302 303 304 |
# File 'lib/chukan.rb', line 302 def pid @pid end |
Class Method Details
.define_finalizer(obj, pid) ⇒ Object
304 305 306 307 308 |
# File 'lib/chukan.rb', line 304 def self.define_finalizer(obj, pid) killer = self.new(pid) ObjectSpace.define_finalizer(obj, self.finalizer(killer)) killer end |
.finalizer(killer) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/chukan.rb', line 310 def self.finalizer(killer) proc { if pid = killer.pid [:SIGTERM, :SIGKILL].each {|sig| Process.kill(sig, pid) break if 10.times { begin if Process.waitpid(pid, Process::WNOHANG) break true end sleep 0.1 rescue break true end nil } } end } end |
Instance Method Details
#killed ⇒ Object
299 300 301 |
# File 'lib/chukan.rb', line 299 def killed @pid = nil end |