Skip to content

Commit

Permalink
better handling of child PIDs and reaping of processes
Browse files Browse the repository at this point in the history
  • Loading branch information
TwP committed Mar 19, 2017
1 parent f625ab1 commit 69c224d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/servolux/child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def stop
# the child process is not running.
#
def wait( flags = 0 )
return if @io.nil?
return if @pid.nil?
_, @status = Process.wait2(@pid, flags) unless @status
exitstatus
end
Expand All @@ -160,7 +160,7 @@ def wait( flags = 0 )
# @return [Boolean]
#
def alive?
return if @io.nil?
return if @pid.nil?
wait(Process::WNOHANG|Process::WUNTRACED)
Process.kill(0, @pid)
true
Expand Down
4 changes: 3 additions & 1 deletion lib/servolux/piper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def self.daemon( nochdir = false, noclose = false )
piper.parent {
pid = piper.gets
raise ::Servolux::Error, 'Could not get the child PID.' if pid.nil?
piper.instance_variable_set(:@child_pid, pid)

piper.wait # reap the child process
piper.instance_variable_set(:@child_pid, pid) # adopt the grandchild
}
piper.child {
Process.setsid # Become session leader.
Expand Down

0 comments on commit 69c224d

Please sign in to comment.