[Title] Fixed to kill all sub process that invoked by job
authordonghee yang <donghee.yang@samsung.com>
Mon, 24 Sep 2012 15:32:45 +0000 (00:32 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Mon, 24 Sep 2012 15:32:45 +0000 (00:32 +0900)
src/build_server/CommonJob.rb
src/common/utils.rb

index 7badfcff2190c0ef285efe8bb98afbe570afd74b..cb6a86d3b2235ee06e54ae01889fb63d66c2f6e6 100644 (file)
@@ -172,8 +172,12 @@ class CommonJob
        protected
        def kill_sub_process()
                if @sub_pid != 0 then
-                       Process.kill("TERM", @sub_pid)
-                       Process.waitpid(@sub_pid)       
-               end
-       end
+               pids = [@sub_pid]
+            pids += Utils.descendant_processes(@sub_pid)
+            pids.each { |pid|
+                 Process.kill("TERM", pid)
+            }
+            Process.waitpid2(@sub_pid)
+        end
+    end
 end
index 8c35fa920a98ca6eed60eaa02a3da197b77c2a4f..b3d1a6be03351b16f30b058b4e74386ca29f3af4 100644 (file)
@@ -537,6 +537,15 @@ class Utils
                return version
        end
 
+    def Utils.descendant_processes(base=Process.pid)
+        descendants = Hash.new{|ht,k| ht[k]=[k]}
+        Hash[*`ps -eo pid,ppid`.scan(/\d+/).map{|x|x.to_i}].each{|pid,ppid|
+                descendants[ppid] << descendants[pid]
+        }       
+        return descendants[base].flatten - [base]
+    end 
+
+
        if defined?(HOST_OS).nil? then
                HOST_OS = Utils.identify_current_OS()
        end