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
25
26
# File 'lib/cloudscopes/process.rb', line 17

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

#exe_nameObject



28
29
30
# File 'lib/cloudscopes/process.rb', line 28

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



32
33
34
35
36
37
38
# File 'lib/cloudscopes/process.rb', line 32

def uid
  begin
    File.stat(procpath('mem')).uid
  rescue Errno::ENOENT => e
    nil
  end
end

#userObject



40
41
42
# File 'lib/cloudscopes/process.rb', line 40

def user
  Etc.getpwuid(uid || 0).name
end