Class: Steam::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '/tmp') ⇒ Process

Returns a new instance of Process.



5
6
7
8
# File 'lib/steam/process.rb', line 5

def initialize(path = '/tmp')
  @path = path
  recall_pid
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/steam/process.rb', line 3

def path
  @path
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/steam/process.rb', line 3

def pid
  @pid
end

Instance Method Details

#fork(options) ⇒ Object



20
21
22
23
24
25
# File 'lib/steam/process.rb', line 20

def fork(options)
  @pid = Kernel.fork { yield }
  write_pid
  # Process.detach(pid) ?
  at_exit { kill } unless options[:keep_alive]
end

#kill(signal = 'TERM') ⇒ Object



27
28
29
30
31
# File 'lib/steam/process.rb', line 27

def kill(signal = 'TERM')
  ::Process.kill(Signal.list[signal], pid)
  delete_pid
  true
end

#pid?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/steam/process.rb', line 10

def pid?
  !!pid
end

#running?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/steam/process.rb', line 14

def running?
  pid? && !!::Process.getpgid(pid)
rescue Errno::ESRCH
  false
end