Class: Phantom::Base
- Inherits:
-
Object
- Object
- Phantom::Base
- Defined in:
- lib/phantom/base.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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, name = nil) ⇒ 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, name = nil) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/phantom/base.rb', line 5 def initialize(pid, name=nil) @pid = pid.nil? ? nil : pid.to_i @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/phantom/base.rb', line 3 def name @name end |
#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
34 35 36 |
# File 'lib/phantom/base.rb', line 34 def abort! kill(:ABRT) if alive? end |
#alive? ⇒ Boolean
67 68 69 |
# File 'lib/phantom/base.rb', line 67 def alive? !dead? end |
#continue ⇒ Object Also known as: resume
50 51 52 53 54 55 |
# File 'lib/phantom/base.rb', line 50 def continue if alive? kill(:CONT) @status = Phantom::Status::ALIVE end end |
#dead? ⇒ Boolean
71 72 73 |
# File 'lib/phantom/base.rb', line 71 def dead? status == Phantom::Status::DEAD end |
#gid ⇒ Object
18 19 20 |
# File 'lib/phantom/base.rb', line 18 def gid @gid ||= Process.getpgid(@pid) end |
#group_priority ⇒ Object
26 27 28 |
# File 'lib/phantom/base.rb', line 26 def group_priority @group_priority ||= Process.getpriority(Process::PRIO_PGRP, @pid) end |
#kill(signal) ⇒ Object
10 11 12 |
# File 'lib/phantom/base.rb', line 10 def kill(signal) Process.kill(signal, @pid) if @pid end |
#process_priority ⇒ Object
30 31 32 |
# File 'lib/phantom/base.rb', line 30 def process_priority @process_priority ||= Process.getpriority(Process::PRIO_PROCESS, @pid) end |
#sid ⇒ Object
14 15 16 |
# File 'lib/phantom/base.rb', line 14 def sid @sid ||= Process.getsid(@pid) end |
#status ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/phantom/base.rb', line 58 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
42 43 44 45 46 47 |
# File 'lib/phantom/base.rb', line 42 def stop if alive? kill(:STOP) @status = Phantom::Status::PAUSED end end |
#terminate ⇒ Object
38 39 40 |
# File 'lib/phantom/base.rb', line 38 def terminate kill(:TERM) if alive? end |
#user_priority ⇒ Object
22 23 24 |
# File 'lib/phantom/base.rb', line 22 def user_priority @user_priority ||= Process.getpriority(Process::PRIO_USER, @pid) end |