Class: Async::Process::Child
- Inherits:
-
Object
- Object
- Async::Process::Child
- Defined in:
- lib/async/process/child.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(*args, **options) ⇒ Child
constructor
A new instance of Child.
- #kill(signal = :TERM) ⇒ Object
- #running? ⇒ Boolean
- #wait ⇒ Object
Constructor Details
#initialize(*args, **options) ⇒ Child
Returns a new instance of Child.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/async/process/child.rb', line 9 def initialize(*args, **) # Setup a cross-thread notification pipe - nio4r can't monitor pids unfortunately: pipe = ::IO.pipe @input = pipe.first @output = pipe.last @exit_status = nil @pid = ::Process.spawn(*args, **, pgroup: true) @thread = Thread.new do _, @exit_status = ::Process.wait2(@pid) @output.close end end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
25 26 27 |
# File 'lib/async/process/child.rb', line 25 def pid @pid end |
Instance Method Details
#kill(signal = :TERM) ⇒ Object
31 32 33 |
# File 'lib/async/process/child.rb', line 31 def kill(signal = :TERM) ::Process.kill(signal, -@pid) end |
#running? ⇒ Boolean
27 28 29 |
# File 'lib/async/process/child.rb', line 27 def running? @exit_status.nil? end |
#wait ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/async/process/child.rb', line 35 def wait if @exit_status.nil? wait_thread end return @exit_status end |