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?
300
300
end
301
301
302
302
# 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
304
305
def kill_child
305
306
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 |
311
311
sleep ( 0.1 )
312
+ return if Process . waitpid ( @child , Process ::WNOHANG )
312
313
end
313
- Process . kill ( "KILL" , @child ) rescue nil
314
+ log! "Sending KILL signal to child #{ @child } "
315
+ Process . kill ( "KILL" , @child )
314
316
else
315
317
log! "Child #{ @child } not found, restarting."
316
318
shutdown
317
319
end
318
320
end
321
+ rescue SystemCallError
322
+ log! "Child #{ @child } already quit."
319
323
end
320
324
321
325
# are we paused?
You can’t perform that action at this time.
0 commit comments