Class: RakeUp::Utilities::ProcessCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/rakeup/utilities/process_check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid) ⇒ ProcessCheck

Returns a new instance of ProcessCheck.



6
7
8
# File 'lib/rakeup/utilities/process_check.rb', line 6

def initialize(pid)
  @pid = pid.to_i
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/rakeup/utilities/process_check.rb', line 4

def error
  @error
end

#pidObject (readonly)

Returns the value of attribute pid.



4
5
6
# File 'lib/rakeup/utilities/process_check.rb', line 4

def pid
  @pid
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
# File 'lib/rakeup/utilities/process_check.rb', line 10

def run
  begin
    info = Process.getpgid(pid)
    @running = true
  rescue Errno::ESRCH => error
    @running = false
    @error = error
  end
end

#running?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rakeup/utilities/process_check.rb', line 20

def running?
  @running
end

#to_sObject



24
25
26
27
28
29
30
# File 'lib/rakeup/utilities/process_check.rb', line 24

def to_s
  if running?
    "Found process running with pid #{pid}"
  else
    "Unable to find process with pid #{pid}: #{@error}"
  end
end