Class: ProcEntry

Inherits:
Object show all
Defined in:
lib/kunoichi/proctable.rb

Overview

Accessory class to access informations about a process

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message}"
  end
end

Instance Attribute Details

#binaryObject

Returns the value of attribute binary.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def binary
  @binary
end

#cmdlineObject

Returns the value of attribute cmdline.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def cmdline
  @cmdline
end

#gidObject

Returns the value of attribute gid.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def gid
  @gid
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def name
  @name
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def parent
  @parent
end

#pidObject

Returns the value of attribute pid.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def pid
  @pid
end

#uidObject

Returns the value of attribute uid.



4
5
6
# File 'lib/kunoichi/proctable.rb', line 4

def uid
  @uid
end