Class: Datacenter::Process
- Inherits:
-
Object
- Object
- Datacenter::Process
- 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
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(pid, shell = nil) ⇒ Process
constructor
A new instance of Process.
- #send_signal(signal) ⇒ Object
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
#pid ⇒ Object (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
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 |