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
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