class Cumuli::PS
Constants
- REGEX
Attributes
lines[R]
Public Class Methods
list()
click to toggle source
# File lib/cumuli/ps.rb, line 102 def self.list `ps axo pid,ppid,comm,args,user` end
new(list=self.class.list)
click to toggle source
# File lib/cumuli/ps.rb, line 7 def initialize(list=self.class.list) lines = list.lines lines.shift # to remove the header @lines = lines.map{|l| Line.new(l) } end
Public Instance Methods
children(pid=root_pid)
click to toggle source
# File lib/cumuli/ps.rb, line 81 def children(pid=root_pid) ppid_hash[pid] end
family(pid=root_pid)
click to toggle source
# File lib/cumuli/ps.rb, line 70 def family(pid=root_pid) collection = [] if kids = children(pid) collection += kids kids.each do |k| collection += family(k) end end collection end
foremans()
click to toggle source
# File lib/cumuli/ps.rb, line 40 def foremans lines.select{|l| l.command.match(/foreman: master/) }.sort end
int(pids=[root_pids])
click to toggle source
# File lib/cumuli/ps.rb, line 44 def int(pids=[root_pids]) pids.compact.each do |pid| Process.kill('INT', pid) end end
kill(pids=[root_pid])
click to toggle source
# File lib/cumuli/ps.rb, line 50 def kill(pids=[root_pid]) pids.compact.each do |pid| Process.kill(9, pid) end end
line(pid=root_pid)
click to toggle source
# File lib/cumuli/ps.rb, line 65 def line(pid=root_pid) line = lines.detect{|l| l.pid == pid } line && line.to_s end
ppid_hash()
click to toggle source
# File lib/cumuli/ps.rb, line 56 def ppid_hash lines .inject({}) do |hash, line| hash[line.ppid] ||= [] hash[line.ppid] << line.pid hash end end
report(pid=root_pid)
click to toggle source
# File lib/cumuli/ps.rb, line 85 def report(pid=root_pid) r = [line(pid).to_s] family(pid).each do |p| l = line(p) r << l.to_s end r.join("\n") end
report_all()
click to toggle source
# File lib/cumuli/ps.rb, line 94 def report_all r = [] foremans.each do |line| r << report(line.pid) end r.join("\n") end
root()
click to toggle source
# File lib/cumuli/ps.rb, line 36 def root foremans.first end
root_pid()
click to toggle source
# File lib/cumuli/ps.rb, line 32 def root_pid root && root.pid end