This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new e08ee02f Try to gather a bit more info
e08ee02f is described below

commit e08ee02f83dce05dd000f7287969d9acb5a585d1
Author: Sebb <s...@apache.org>
AuthorDate: Sun Dec 17 13:06:27 2023 +0000

    Try to gather a bit more info
---
 tools/site-scan.rb | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/site-scan.rb b/tools/site-scan.rb
index 8a3f3ddc..aad4a2ea 100755
--- a/tools/site-scan.rb
+++ b/tools/site-scan.rb
@@ -224,22 +224,32 @@ def exec_with_timeout(cmd, timeout)
     $stderr.puts "WARN:  #{Time.now} timeout scanning #{cmd[-1]} #{pid}"
     stderr = 'Timeout'
     ret=''
+    # Try to show process tree
+    cmd = "ps -lfg #{pid}"
     begin
+      $stderr.puts "WARN:  #{Time.now} #{cmd}:"
+      $stderr.puts `#{cmd}`
+      reaper = Process.detach(pid) # ensure the process is reaped
       # kill -pid responds with EINVAL - invalid argument
       $stderr.puts "WARN:  #{Time.now} about to kill -15 #{pid}"
       ret = Process.kill(-15, pid) # SIGTERM
       $stderr.puts "WARN:  #{Time.now} sent kill -15 #{pid} ret=#{ret}"
 
-      sleep 30 # allow some time for process to exit
+      thrd = reaper.join 30 # allow some time for process to exit
 
-      $stderr.puts "WARN:  #{Time.now} about to kill -9 #{pid}"
-      ret = Process.kill(-9, pid) # SIGKILL
-      $stderr.puts "WARN:  #{Time.now} sent kill -9 #{pid} ret=#{ret}"
+      if thrd # original process has finished
+        $stderr.puts  "WARN:  #{Time.now} process completed #{thrd.value}"
+      else # not yet finished, try a stronger kill
+        $stderr.puts "WARN:  #{Time.now} about to kill -9 #{pid}"
+        ret = Process.kill(-9, pid) # SIGKILL
+        $stderr.puts "WARN:  #{Time.now} sent kill -9 #{pid} ret=#{ret}"
+      end
     rescue StandardError => e
       $stderr.puts "WARN:  #{Time.now} ret=#{ret} exception: #{e}"
     end
-    Process.detach(pid)
-  ensure
+    $stderr.puts "WARN:  #{Time.now} #{cmd}:"
+    $stderr.puts `#{cmd}`
+ensure
     wout.close unless wout.closed?
     werr.close unless werr.closed?
     # dispose the read ends of the pipes

Reply via email to