Class: Cloudscopes::Process::SystemProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscopes/process.rb

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ SystemProcess

Returns a new instance of SystemProcess.



8
9
10
11
# File 'lib/cloudscopes/process.rb', line 8

def initialize(id)
  @id = id.to_i
  raise "Invalid system process id #{id}" unless @id > 0 && @id <= 65536
end

Instance Method Details

#exeObject



17
18
19
20
21
22
23
24
# File 'lib/cloudscopes/process.rb', line 17

def exe
  begin
    File.readlink(procpath('exe'))
  rescue SystemCallError => e # report and ignore
    $stderr.puts "Error accessing process #{@id}: #{e.message}"
    ''
  end
end

#exe_nameObject



26
27
28
# File 'lib/cloudscopes/process.rb', line 26

def exe_name
  File.basename(exe)
end

#procpath(field = nil) ⇒ Object



13
14
15
# File 'lib/cloudscopes/process.rb', line 13

def procpath(field = nil)
  "/proc/#{@id}/#{field}"
end

#uidObject



30
31
32
# File 'lib/cloudscopes/process.rb', line 30

def uid
  File.stat(procpath('mem')).uid
end

#userObject



34
35
36
# File 'lib/cloudscopes/process.rb', line 34

def user
  Etc.getpwuid(uid).name
end