Class: Cloudscopes::Process::SystemProcess
- Inherits:
-
Object
- Object
- Cloudscopes::Process::SystemProcess
show all
- Defined in:
- lib/cloudscopes/process.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SystemProcess.
8
9
10
11
12
|
# File 'lib/cloudscopes/process.rb', line 8
def initialize(id)
@id = id.to_i
@@maxpid ||= File.read('/proc/sys/kernel/pid_max').to_i
raise "Invalid system process id #{id}" unless @id > 0 && @id < @@maxpid
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/cloudscopes/process.rb', line 18
def method_missing(name, *args)
raise ArgumentError.new("wrong number of arguments (#{args.length} for 0)") unless args.length == 0
begin
File.read(procpath(name.to_s))
rescue Errno::ENOENT => e
''
rescue SystemCallError => e
$stderr.puts "Error accessing process #{@id}: #{e.class}:#{e.message}"
''
end
end
|
Instance Method Details
#exe ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cloudscopes/process.rb', line 30
def exe
begin
File.readlink(procpath('exe'))
rescue Errno::ENOENT => e
''
rescue SystemCallError => e
$stderr.puts "Error accessing process #{@id}: #{e.class}:#{e.message}"
''
end
end
|
#exe_name ⇒ Object
41
42
43
|
# File 'lib/cloudscopes/process.rb', line 41
def exe_name
File.basename(exe)
end
|
57
58
59
|
# File 'lib/cloudscopes/process.rb', line 57
def
statm.strip.split(/\s+/)[1].to_i * Etc.sysconf(Etc::SC_PAGESIZE)
end
|
#mem_usage_virt ⇒ Object
Also known as:
mem_usage
60
61
62
|
# File 'lib/cloudscopes/process.rb', line 60
def mem_usage_virt
statm.strip.split(/\s+/)[0].to_i * Etc.sysconf(Etc::SC_PAGESIZE)
end
|
#procpath(field = nil) ⇒ Object
14
15
16
|
# File 'lib/cloudscopes/process.rb', line 14
def procpath(field = nil)
"/proc/#{@id}/#{field}"
end
|
#uid ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/cloudscopes/process.rb', line 45
def uid
begin
File.stat(procpath('mem')).uid
rescue Errno::ENOENT => e
nil
end
end
|
#user ⇒ Object
53
54
55
|
# File 'lib/cloudscopes/process.rb', line 53
def user
Etc.getpwuid(uid || 0).name
end
|