Class: Phantom::Base
- Inherits:
-
Object
- Object
- Phantom::Base
- Defined in:
- lib/phantom/base.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #abort! ⇒ Object
- #alive? ⇒ Boolean
- #continue ⇒ Object (also: #resume)
- #dead? ⇒ Boolean
- #gid ⇒ Object
- #group_priority ⇒ Object
-
#initialize(pid) ⇒ Base
constructor
A new instance of Base.
- #kill(signal) ⇒ Object
- #process_priority ⇒ Object
- #sid ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object (also: #pause)
- #terminate ⇒ Object
- #user_priority ⇒ Object
Constructor Details
#initialize(pid) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/phantom/base.rb', line 5 def initialize(pid) @pid = pid.nil? ? nil : pid.to_i end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/phantom/base.rb', line 3 def pid @pid end |
Instance Method Details
#abort! ⇒ Object
33 34 35 |
# File 'lib/phantom/base.rb', line 33 def abort! kill(:ABRT) if alive? end |
#alive? ⇒ Boolean
66 67 68 |
# File 'lib/phantom/base.rb', line 66 def alive? !dead? end |
#continue ⇒ Object Also known as: resume
49 50 51 52 53 54 |
# File 'lib/phantom/base.rb', line 49 def continue if alive? kill(:CONT) @status = Phantom::Status::ALIVE end end |
#dead? ⇒ Boolean
70 71 72 |
# File 'lib/phantom/base.rb', line 70 def dead? status == Phantom::Status::DEAD end |
#gid ⇒ Object
17 18 19 |
# File 'lib/phantom/base.rb', line 17 def gid @gid ||= Process.getpgid(@pid) end |
#group_priority ⇒ Object
25 26 27 |
# File 'lib/phantom/base.rb', line 25 def group_priority @group_priority ||= Process.getpriority(Process::PRIO_PGRP, @pid) end |
#kill(signal) ⇒ Object
9 10 11 |
# File 'lib/phantom/base.rb', line 9 def kill(signal) Process.kill(signal, @pid) if @pid end |
#process_priority ⇒ Object
29 30 31 |
# File 'lib/phantom/base.rb', line 29 def process_priority @process_priority ||= Process.getpriority(Process::PRIO_PROCESS, @pid) end |
#sid ⇒ Object
13 14 15 |
# File 'lib/phantom/base.rb', line 13 def sid @sid ||= Process.getsid(@pid) end |
#status ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/phantom/base.rb', line 57 def status begin Process.kill(0, @pid) return @status ||= Phantom::Status::ALIVE rescue Errno::ESRCH return @status = Phantom::Status::DEAD end end |
#stop ⇒ Object Also known as: pause
41 42 43 44 45 46 |
# File 'lib/phantom/base.rb', line 41 def stop if alive? kill(:STOP) @status = Phantom::Status::PAUSED end end |
#terminate ⇒ Object
37 38 39 |
# File 'lib/phantom/base.rb', line 37 def terminate kill(:TERM) if alive? end |
#user_priority ⇒ Object
21 22 23 |
# File 'lib/phantom/base.rb', line 21 def user_priority @user_priority ||= Process.getpriority(Process::PRIO_USER, @pid) end |