Class: ProcEntry
Overview
Accessory class to access informations about a process
Instance Attribute Summary collapse
-
#binary ⇒ Object
Returns the value of attribute binary.
-
#cmdline ⇒ Object
Returns the value of attribute cmdline.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
-
#initialize(pid) ⇒ ProcEntry
constructor
Fetch all the values when the object is created.
Constructor Details
#initialize(pid) ⇒ ProcEntry
Fetch all the values when the object is created
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kunoichi/proctable.rb', line 7 def initialize(pid) raise 'invalid pid: not a number' unless pid.is_a? Fixnum pids = pid.to_s raise 'invalid pid: not running' unless File.directory? "/proc/#{pids}" begin @pid = pid @cmdline = File.read("/proc/#{pids}/cmdline").gsub("\0", ' ') @name = @cmdline.split[0] @uid = File.stat("/proc/#{pids}/").uid @gid = File.stat("/proc/#{pids}/").gid @binary = File.readlink("/proc/#{pids}/exe") @parent = File.readlines("/proc/#{pids}/status").grep(/^PPid:/).first.split[1].to_i rescue => e raise "can't get process info: #{e.}" end end |
Instance Attribute Details
#binary ⇒ Object
Returns the value of attribute binary.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def binary @binary end |
#cmdline ⇒ Object
Returns the value of attribute cmdline.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def cmdline @cmdline end |
#gid ⇒ Object
Returns the value of attribute gid.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def gid @gid end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def parent @parent end |
#pid ⇒ Object
Returns the value of attribute pid.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def pid @pid end |
#uid ⇒ Object
Returns the value of attribute uid.
4 5 6 |
# File 'lib/kunoichi/proctable.rb', line 4 def uid @uid end |