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|
+
+ # generate pid => ppid hash
+ # NOTE. MinGW does not support "-o" option and has different output format
+ rel_hash = nil
+ os_category = get_os_category(HOST_OS)
+ if os_category != "windows" then
+ rel_hash = Hash[*`ps -eo pid,ppid`.scan(/\d+/).map{|x| x.to_i}]
+ else
+ rel_hash = Hash[*`ps -e`.scan(/^[\t\s]*(\d+)[\t\s]+(\d+)/).flatten.map{|x| x.to_i}]
+ end
+
+ # make pid => all descendent processes
+ rel_hash.each{|pid,ppid|
descendants[ppid] << descendants[pid]
}
return descendants[base].flatten - [base]