class ChildProcess::Unix::Process
Attributes
pid[R]
Public Instance Methods
exited?()
click to toggle source
# 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
io()
click to toggle source
# File lib/childprocess/unix/process.rb, line 6 def io @io ||= Unix::IO.new end
stop(timeout = 3)
click to toggle source
# 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
wait()
click to toggle source
# 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
Private Instance Methods
_pid()
click to toggle source
# File lib/childprocess/unix/process.rb, line 76 def _pid if leader? -@pid # negative pid == process group else @pid end end
send_kill()
click to toggle source
# File lib/childprocess/unix/process.rb, line 61 def send_kill send_signal 'KILL' end
send_signal(sig)
click to toggle source
# File lib/childprocess/unix/process.rb, line 65 def send_signal(sig) assert_started log "sending #{sig}" ::Process.kill sig, _pid end
send_term()
click to toggle source
# File lib/childprocess/unix/process.rb, line 57 def send_term send_signal 'TERM' end
set_exit_code(status)
click to toggle source
# File lib/childprocess/unix/process.rb, line 72 def set_exit_code(status) @exit_code = status.exitstatus || status.termsig end