Class: Datacenter::Process

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

Constant Summary collapse

ATTRIBUTES =
[
  :command, 
  :status, 
  :memory, 
  :virtual_memory,
  :cpu,
  :user,
  :name,
  :cpu_usage,
  :mem_usage
]
EXPIRATION_TIME =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid, shell = nil) ⇒ Process

Returns a new instance of Process.



20
21
22
23
24
# File 'lib/datacenter/process.rb', line 20

def initialize(pid, shell=nil)
  @pid = pid
  @shell = shell || Shell::Local.new
  @cache = Cache.new EXPIRATION_TIME
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



18
19
20
# File 'lib/datacenter/process.rb', line 18

def pid
  @pid
end

Instance Method Details

#alive?Boolean

Returns:



32
33
34
35
36
# File 'lib/datacenter/process.rb', line 32

def alive?
  alive = !shell.run("ps -p #{pid} | grep #{pid}").empty?
  Datacenter.logger.debug(self.class) { "pid: #{pid} - ALIVE: #{alive}" } if !alive
  alive
end

#send_signal(signal) ⇒ Object



38
39
40
# File 'lib/datacenter/process.rb', line 38

def send_signal(signal)
  shell.run "kill -s #{signal} #{pid}"
end