/usr/lib/ruby/vendor_ruby/childprocess/unix/process.rb is in ruby-childprocess 0.5.9-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | module ChildProcess
module Unix
class Process < AbstractProcess
attr_reader :pid
def io
@io ||= Unix::IO.new
end
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
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
rescue Errno::ECHILD
# may be thrown for detached processes
true
end
def wait
assert_started
if exited?
exit_code
else
_, status = ::Process.waitpid2 _pid
set_exit_code(status)
end
end
private
def send_term
send_signal 'TERM'
end
def send_kill
send_signal 'KILL'
end
def send_signal(sig)
assert_started
log "sending #{sig}"
::Process.kill sig, _pid
end
def set_exit_code(status)
@exit_code = status.exitstatus || status.termsig
end
def _pid
if leader?
-@pid # negative pid == process group
else
@pid
end
end
end # Process
end # Unix
end # ChildProcess
|