From: donghee yang Date: Mon, 24 Sep 2012 15:32:45 +0000 (+0900) Subject: [Title] Fixed to kill all sub process that invoked by job X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2f4d9c23e8af5cae3651367ce461efdbb02a0640;p=sdk%2Ftools%2Fsdk-build.git [Title] Fixed to kill all sub process that invoked by job --- diff --git a/src/build_server/CommonJob.rb b/src/build_server/CommonJob.rb index 7badfcf..cb6a86d 100644 --- a/src/build_server/CommonJob.rb +++ b/src/build_server/CommonJob.rb @@ -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 diff --git a/src/common/utils.rb b/src/common/utils.rb index 8c35fa9..b3d1a6b 100644 --- a/src/common/utils.rb +++ b/src/common/utils.rb @@ -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