Module: Smartguard::ProcessManager

Defined in:
lib/smartguard/process_manager.rb

Class Method Summary collapse

Class Method Details

.handle_sigchld(signal) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/smartguard/process_manager.rb', line 13

def self.handle_sigchld(signal)
  pids = []
  @tracked ||= {}

  begin
    loop do
      pid = ::Process.wait(-1, ::Process::WNOHANG)
      break if pid.nil?

      pids << pid
    end
  rescue => e
  end

  pids.each do |pid|
    tracker = @tracked[pid]
    unless tracker.nil?
      @tracked.delete pid
      tracker.call pid
    end
  end
end

.initObject



36
37
38
# File 'lib/smartguard/process_manager.rb', line 36

def self.init
  trap :CHLD, ProcessManager.method(:handle_sigchld)
end

.track(pid, method) ⇒ Object



3
4
5
6
# File 'lib/smartguard/process_manager.rb', line 3

def self.track(pid, method)
  @tracked ||= {}
  @tracked[pid] = method
end

.untrack(pid) ⇒ Object



8
9
10
11
# File 'lib/smartguard/process_manager.rb', line 8

def self.untrack(pid)
  @tracked ||= {}
  @tracked.delete pid
end