Class: MultiForkr

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_forkr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forklets) ⇒ MultiForkr

Returns a new instance of MultiForkr.

Parameters:

  • forklets

    Hash<Object, Integer> the worker objects, with counts



16
17
18
19
20
21
# File 'lib/multi_forkr.rb', line 16

def initialize(forklets)
  @child_defs = forklets
  @master_pid = $$
  @child_sets = Hash.new { |h, k| h[k] = Array.new }
  @in_shutdown = false
end

Instance Attribute Details

#child_defsObject (readonly)

Child Process Definitions



9
10
11
# File 'lib/multi_forkr.rb', line 9

def child_defs
  @child_defs
end

#child_setsObject (readonly)

Child process pids.



13
14
15
# File 'lib/multi_forkr.rb', line 13

def child_sets
  @child_sets
end

#master_pidFixnum (readonly)

The PID of the Forkr master

Returns:

  • (Fixnum)


5
6
7
# File 'lib/multi_forkr.rb', line 5

def master_pid
  @master_pid
end

Instance Method Details

#runnil

Start the master, and spawn workers

Returns:

  • (nil)


25
26
27
28
29
30
31
32
# File 'lib/multi_forkr.rb', line 25

def run
  @inbound, @outbound = IO.pipe
  Signal.trap('CHLD') { dead_child }
  Signal.trap('INT') { interrupt }
  Signal.trap('TERM') { shutdown }
  Signal.trap('QUIT') { core_dump_quit }
  master_loop
end