File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -300,22 +300,26 @@ def shutdown?
300300 end
301301
302302 # Kills the forked child immediately with minimal remorse. The job it
303- # is processing will not be completed.
303+ # is processing will not be completed. Send the child a TERM signal,
304+ # wait 5 seconds, and then a KILL signal if it has not quit
304305 def kill_child
305306 if @child
306- log! "Killing child at #{ @child } "
307- if system ( "ps -o pid,state -p #{ @child } " )
308- Process . kill ( "TERM" , @child ) rescue nil
309- 10 . times do
310- return unless system ( "ps -o pid,state -p #{ @child } " )
307+ unless Process . waitpid ( @child , Process ::WNOHANG )
308+ log! "Sending TERM signal to child #{ @child } "
309+ Process . kill ( "TERM" , @child )
310+ 50 . times do |i |
311311 sleep ( 0.1 )
312+ return if Process . waitpid ( @child , Process ::WNOHANG )
312313 end
313- Process . kill ( "KILL" , @child ) rescue nil
314+ log! "Sending KILL signal to child #{ @child } "
315+ Process . kill ( "KILL" , @child )
314316 else
315317 log! "Child #{ @child } not found, restarting."
316318 shutdown
317319 end
318320 end
321+ rescue SystemCallError
322+ log! "Child #{ @child } already quit."
319323 end
320324
321325 # are we paused?
You can’t perform that action at this time.
0 commit comments