Sha256: efc755a3e6d6129c70732864717a9e3f5d684383845c1575e253d78549b107e4
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
module DeepTest class Warlock def initialize @demons = [] end def start(name, &block) begin pid = Process.fork do Signal.trap("HUP") { exit 0 } yield exit end raise "fatal: fork returned nil" if pid.nil? @demons << [name, pid] puts "Started #{name} (#{pid})" rescue => e puts "exception starting #{name}: #{e}" puts "\t" + e.backtrace.join("\n\t") end end def stop_all @demons.reverse.each do |demon| name, pid = demon if running?(pid) Process.kill("HUP", pid) end end @demons.each do |demon| name, pid = demon begin Process.wait(pid) rescue Errno::ECHILD => e puts e end puts "Stopped #{name} (#{pid})" end end #stolen from daemons def running?(pid) # Check if process is in existence # The simplest way to do this is to send signal '0' # (which is a single system call) that doesn't actually # send a signal begin Process.kill(0, pid) return true rescue Errno::ESRCH return false rescue ::Exception # for example on EPERM (process exists but does not belong to us) return true #rescue Errno::EPERM # return false end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
deep_test-1.1.1 | lib/deep_test/warlock.rb |
deep_test-1.1.2 | lib/deep_test/warlock.rb |
deep_test-1.1.0 | lib/deep_test/warlock.rb |