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
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid, shell = nil) ⇒ Process

Returns a new instance of Process.



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

def initialize(pid, shell=nil)
  @pid = pid
  @shell = shell || Shell::Local.new
  @cache = Cache.new Datacenter.process_cache_expiration
  @mutex = Mutex.new
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



16
17
18
# File 'lib/datacenter/process.rb', line 16

def pid
  @pid
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/datacenter/process.rb', line 31

def alive?
  command = %Q{
    if [ -d "#{proc_dir}" ]; then 
      echo -n "true"
    else
      echo -n "false"
    fi
  }

  alive = shell.run(command) == 'true'

  Datacenter.logger.info(self.class) { "pid: #{pid} - ALIVE: #{alive}" } if !alive
  alive
end

#send_signal(signal) ⇒ Object



46
47
48
# File 'lib/datacenter/process.rb', line 46

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