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) ⇒ 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

#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



33
34
35
# File 'lib/phantom/base.rb', line 33

def abort!
  kill(:ABRT) if alive?
end

#alive?Boolean

Returns:

  • (Boolean)


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

def alive?
  !dead?
end

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

Returns:

  • (Boolean)


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

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

#gidObject



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

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

#group_priorityObject



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_priorityObject



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

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

#sidObject



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

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

#statusObject



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

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

#terminateObject



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

def terminate
  kill(:TERM) if alive?
end

#user_priorityObject



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

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