Class: ChildProcess::Unix::Process

Inherits:
AbstractProcess show all
Defined in:
lib/childprocess/unix/process.rb

Direct Known Subclasses

ForkExecProcess, PosixSpawnProcess

Constant Summary

Constants inherited from AbstractProcess

AbstractProcess::POLL_INTERVAL

Instance Attribute Summary collapse

Attributes inherited from AbstractProcess

#cwd, #detach, #duplex, #environment, #exit_code, #leader

Instance Method Summary collapse

Methods inherited from AbstractProcess

#alive?, #crashed?, #initialize, #poll_for_exit, #start

Constructor Details

This class inherits a constructor from ChildProcess::AbstractProcess

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid



4
5
6
# File 'lib/childprocess/unix/process.rb', line 4

def pid
  @pid
end

Instance Method Details

#exited?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/childprocess/unix/process.rb', line 28

def exited?
  return true if @exit_code

  assert_started
  pid, status = ::Process.waitpid2(_pid, ::Process::WNOHANG | ::Process::WUNTRACED)
  pid = nil if pid == 0 # may happen on jruby

  log(:pid => pid, :status => status)

  if pid
    set_exit_code(status)
  end

  !!pid
end

#ioObject



6
7
8
# File 'lib/childprocess/unix/process.rb', line 6

def io
  @io ||= Unix::IO.new
end

#stop(timeout = 3) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/childprocess/unix/process.rb', line 10

def stop(timeout = 3)
  assert_started
  send_term

  begin
    return poll_for_exit(timeout)
  rescue TimeoutError
    # try next
  end

  send_kill
  wait
rescue Errno::ECHILD, Errno::ESRCH
  # handle race condition where process dies between timeout
  # and send_kill
  true
end

#waitObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/childprocess/unix/process.rb', line 44

def wait
  assert_started

  if exited?
    exit_code
  else
    _, status = ::Process.waitpid2 _pid
    set_exit_code(status)
  end
end