Class: Phantom::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/phantom/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/phantom/base.rb', line 3

def name
  @name
end

#pidObject (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

Returns:

  • (Boolean)


67
68
69
# File 'lib/phantom/base.rb', line 67

def alive?
  !dead?
end

#continueObject 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

Returns:

  • (Boolean)


71
72
73
# File 'lib/phantom/base.rb', line 71

def dead?
  status == Phantom::Status::DEAD
end

#gidObject



18
19
20
# File 'lib/phantom/base.rb', line 18

def gid
  @gid ||= Process.getpgid(@pid)
end

#group_priorityObject



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_priorityObject



30
31
32
# File 'lib/phantom/base.rb', line 30

def process_priority
  @process_priority ||= Process.getpriority(Process::PRIO_PROCESS, @pid)
end

#sidObject



14
15
16
# File 'lib/phantom/base.rb', line 14

def sid
  @sid ||= Process.getsid(@pid)
end

#statusObject



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

#stopObject 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

#terminateObject



38
39
40
# File 'lib/phantom/base.rb', line 38

def terminate
  kill(:TERM) if alive?
end

#user_priorityObject



22
23
24
# File 'lib/phantom/base.rb', line 22

def user_priority
  @user_priority ||= Process.getpriority(Process::PRIO_USER, @pid)
end