Class: PsProcessList

Inherits:
Array
  • Object
show all
Defined in:
lib/ps-ruby/ps-ruby.rb

Instance Method Summary collapse

Instance Method Details

#find_processes(name) ⇒ Object



37
38
39
# File 'lib/ps-ruby/ps-ruby.rb', line 37

def find_processes(name)
  find_processes_by("COMMAND", name)
end

#find_processes_by(attr_name, value) ⇒ Object



41
42
43
44
# File 'lib/ps-ruby/ps-ruby.rb', line 41

def find_processes_by(attr_name, value)
  regex = if value.class != Regexp then Regexp.new(".*#{value}.*", Regexp::IGNORECASE) else value end
  PsProcessList.new(self.select{|x| x[attr_name] =~ regex })
end

#kill!Object



14
15
16
# File 'lib/ps-ruby/ps-ruby.rb', line 14

def kill!
  self.each(&:kill!)
end

#pick_by_attr(attr_name) ⇒ Object



46
47
48
# File 'lib/ps-ruby/ps-ruby.rb', line 46

def pick_by_attr(attr_name)
  self.map{|x| x[attr_name] } if PS.attrs.include?(attr_name)
end

#simple_display(limit_process_name_len = 30) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ps-ruby/ps-ruby.rb', line 18

def simple_display(limit_process_name_len=30)
  picks = ["PID", "%CPU", "%MEM", "COMMAND"]
  if self.size > 0
    puts picks.join("\t")+"\n"
    self.each{|x|
      puts picks.reduce(""){|s, k| 
        s += if k == "COMMAND" and x[k].size > limit_process_name_len then 
          "#{x[k][0..limit_process_name_len]}...\t" 
        else 
          "#{x[k]}\t" 
        end 
      }
    }
  else
    puts "Not found any process called `#{name}`"
  end
  nil
end