Module: ProcessTree
- Defined in:
- lib/clarity/process_tree.rb
Class Method Summary collapse
Class Method Details
.child_pids_of(ppid) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/clarity/process_tree.rb', line 11 def self.child_pids_of(ppid) out = `ps -opid,ppid | grep #{ppid.to_s}` ids = out.split("\n").map {|line| $1 if line =~ /^\s*([0-9]+)\s.*/ }.compact ids.delete(ppid.to_s) if ids.empty? ids else ids << ids.map {|id| child_pids_of(id) } end end |
.kill(ppid) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/clarity/process_tree.rb', line 3 def self.kill(ppid) return if ppid.nil? all_pids = [ppid] + child_pids_of(ppid).flatten.uniq.compact all_pids.each do |pid| Process.kill('TERM',pid.to_i) rescue nil end end |