Class: God::System::Process

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid) ⇒ Process

Returns a new instance of Process.



13
14
15
16
# File 'lib/god/system/process.rb', line 13

def initialize(pid)
  @pid = pid.to_i
  @poller = self.class.fetch_system_poller.new(@pid)
end

Class Method Details

.fetch_system_pollerObject



5
6
7
8
9
10
11
# File 'lib/god/system/process.rb', line 5

def self.fetch_system_poller
  @@poller ||= if SlashProcPoller.usable?
   SlashProcPoller
 else
   PortablePoller
 end
end

Instance Method Details

#exists?Boolean

Return true if this process is running, false otherwise

Returns:

  • (Boolean)


19
20
21
# File 'lib/god/system/process.rb', line 19

def exists?
  !!::Process.kill(0, @pid) rescue false
end

#memoryObject

Memory usage in kilobytes (resident set size)



24
25
26
# File 'lib/god/system/process.rb', line 24

def memory
  @poller.memory
end

#percent_cpuObject

Percentage CPU usage



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

def percent_cpu
  @poller.percent_cpu
end

#percent_memoryObject

Percentage memory usage



29
30
31
# File 'lib/god/system/process.rb', line 29

def percent_memory
  @poller.percent_memory
end