Class: Forkr
- Inherits:
-
Object
- Object
- Forkr
- Defined in:
- lib/forkr.rb
Instance Attribute Summary collapse
-
#child_count ⇒ Integer
readonly
The number of children I should maintain This can be adjusted up or down with the TTIN and TTOU signals.
-
#children ⇒ Array<Fixnum>
readonly
Child process pids.
-
#master_pid ⇒ Fixnum
readonly
The PID of the Forkr master.
Instance Method Summary collapse
-
#initialize(forklet, num_kids = 1) ⇒ Forkr
constructor
A new instance of Forkr.
-
#run ⇒ nil
Start the master, and spawn workers.
Constructor Details
#initialize(forklet, num_kids = 1) ⇒ Forkr
Returns a new instance of Forkr.
18 19 20 21 22 23 24 |
# File 'lib/forkr.rb', line 18 def initialize(forklet, num_kids = 1) @worker_client = forklet @master_pid = $$ @children = [] @child_count = num_kids @in_shutdown = false end |
Instance Attribute Details
#child_count ⇒ Integer (readonly)
The number of children I should maintain This can be adjusted up or down with the TTIN and TTOU signals.
10 11 12 |
# File 'lib/forkr.rb', line 10 def child_count @child_count end |
#children ⇒ Array<Fixnum> (readonly)
Child process pids.
14 15 16 |
# File 'lib/forkr.rb', line 14 def children @children end |
#master_pid ⇒ Fixnum (readonly)
The PID of the Forkr master
5 6 7 |
# File 'lib/forkr.rb', line 5 def master_pid @master_pid end |
Instance Method Details
#run ⇒ nil
Start the master, and spawn workers
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/forkr.rb', line 28 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 } Signal.trap('TTIN') { add_worker } Signal.trap('TTOU') { remove_worker } master_loop end |