Class: Async::Process::Child

Inherits:
Object
  • Object
show all
Defined in:
lib/async/process/child.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **options) ⇒ Child

Returns a new instance of Child.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/async/process/child.rb', line 26

def initialize(*args, **options)
	# Setup a cross-thread notification pipe - nio4r can't monitor pids unfortunately:
	pipe = ::IO.pipe
	@input = Async::IO::Generic.new(pipe.first)
	@output = pipe.last
	
	@exit_status = nil
	
	@pid = ::Process.spawn(*args, **options, pgroup: true)
	
	@thread = Thread.new do
		_, @exit_status = ::Process.wait2(@pid)
		@output.close
	end
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



42
43
44
# File 'lib/async/process/child.rb', line 42

def pid
  @pid
end

Instance Method Details

#kill(signal = :TERM) ⇒ Object



48
49
50
# File 'lib/async/process/child.rb', line 48

def kill(signal = :TERM)
	::Process.kill(signal, -@pid)
end

#running?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/async/process/child.rb', line 44

def running?
	@exit_status.nil?
end

#waitObject



52
53
54
55
56
57
58
# File 'lib/async/process/child.rb', line 52

def wait
	if @exit_status.nil?
		wait_thread
	end
	
	return @exit_status
end