Class: PS::Process
- Inherits:
-
Object
- Object
- PS::Process
- Defined in:
- lib/ps/process.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #display ⇒ Object
- #has ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(data) ⇒ Process
constructor
A new instance of Process.
- #kill!(sig = nil) ⇒ Object
- #mem ⇒ Object
Constructor Details
#initialize(data) ⇒ Process
Returns a new instance of Process.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ps/process.rb', line 16 def initialize data @data = {} data.each do |key,value| @data[key] = case value when /^\-?\d+$/ value.to_i when /^\-?\d+\.\d+$/ value.to_f else value.strip end end end |
Instance Method Details
#alive? ⇒ Boolean
43 44 45 46 47 48 49 |
# File 'lib/ps/process.rb', line 43 def alive? return unless pid ::Process.getpgid(pid) true rescue Errno::ESRCH false end |
#display ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ps/process.rb', line 51 def display disp = [] disp << pid disp << user disp << lstart disp << pcpu disp << pmem disp << mem disp << command disp.compact.join(' ') end |
#has ⇒ Object
35 36 37 |
# File 'lib/ps/process.rb', line 35 def has @data.keys end |
#include?(value) ⇒ Boolean
31 32 33 |
# File 'lib/ps/process.rb', line 31 def include? value @data.has_key?(value.to_s) end |
#kill!(sig = nil) ⇒ Object
63 64 65 66 |
# File 'lib/ps/process.rb', line 63 def kill!(sig=nil) sig ||= 'INT' ::Process.kill(sig, pid) if pid end |
#mem ⇒ Object
39 40 41 |
# File 'lib/ps/process.rb', line 39 def mem rss/1024.0 if rss end |