Class: Arachni::Processes::Manager
- Includes:
- Singleton
- Defined in:
- lib/arachni/processes/manager.rb
Overview
Helper for managing processes.
Instance Attribute Summary collapse
-
#pids ⇒ Array<Integer>
readonly
PIDs of all running processes.
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(pid) ⇒ Integer
‘pid`.
- #discard_output(&block) ⇒ Object
- #fork_em(*args, &block) ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #kill(pid) ⇒ Object
-
#kill_em ⇒ Object
Stops the EventMachine reactor.
- #kill_many(pids) ⇒ Object
-
#killall ⇒ Object
Kills all processes.
-
#preserve_output ⇒ Object
Overrides the default setting of discarding process outputs.
- #quiet_fork(&block) ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
34 35 36 37 |
# File 'lib/arachni/processes/manager.rb', line 34 def initialize @pids = [] @discard_output = true end |
Instance Attribute Details
#pids ⇒ Array<Integer> (readonly)
Returns PIDs of all running processes.
32 33 34 |
# File 'lib/arachni/processes/manager.rb', line 32 def pids @pids end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/arachni/processes/manager.rb', line 114 def self.method_missing( sym, *args, &block ) if instance.respond_to?( sym ) instance.send( sym, *args, &block ) elsif super( sym, *args, &block ) end end |
.respond_to?(m) ⇒ Boolean
122 123 124 |
# File 'lib/arachni/processes/manager.rb', line 122 def self.respond_to?( m ) super( m ) || instance.respond_to?( m ) end |
Instance Method Details
#<<(pid) ⇒ Integer
Returns ‘pid`.
45 46 47 48 49 |
# File 'lib/arachni/processes/manager.rb', line 45 def <<( pid ) @pids << pid Process.detach pid pid end |
#discard_output(&block) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/arachni/processes/manager.rb', line 99 def discard_output( &block ) if !block_given? @discard_output = true return end proc do if @discard_output $stdout.reopen( '/dev/null', 'w' ) $stderr.reopen( '/dev/null', 'w' ) end block.call end end |
#fork_em(*args, &block) ⇒ Object
89 90 91 |
# File 'lib/arachni/processes/manager.rb', line 89 def fork_em( *args, &block ) self << ::EM.fork_reactor( *args, &discard_output( &block ) ) end |
#kill(pid) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/arachni/processes/manager.rb', line 52 def kill( pid ) loop do begin Process.kill( 'KILL', pid ) rescue Errno::ESRCH @pids.delete pid return end end end |
#kill_em ⇒ Object
Stops the EventMachine reactor.
75 76 77 78 79 |
# File 'lib/arachni/processes/manager.rb', line 75 def kill_em ::EM.stop while ::EM.reactor_running? && sleep( 0.1 ) rescue nil end |
#kill_many(pids) ⇒ Object
64 65 66 |
# File 'lib/arachni/processes/manager.rb', line 64 def kill_many( pids ) pids.each { |pid| kill pid } end |
#killall ⇒ Object
Kills all processes.
69 70 71 72 |
# File 'lib/arachni/processes/manager.rb', line 69 def killall kill_many @pids.dup @pids.clear end |
#preserve_output ⇒ Object
Overrides the default setting of discarding process outputs.
94 95 96 |
# File 'lib/arachni/processes/manager.rb', line 94 def preserve_output @discard_output = false end |
#quiet_fork(&block) ⇒ Object
82 83 84 |
# File 'lib/arachni/processes/manager.rb', line 82 def quiet_fork( &block ) self << fork( &discard_output( &block ) ) end |