Class: Cod::Process
- Inherits:
-
Object
- Object
- Cod::Process
- Defined in:
- lib/cod/process.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #channel ⇒ Object
-
#initialize(command, serializer = nil) ⇒ Process
constructor
A new instance of Process.
- #kill ⇒ Object
- #run(command) ⇒ Object
- #terminate ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(command, serializer = nil) ⇒ Process
Returns a new instance of Process.
5 6 7 8 9 |
# File 'lib/cod/process.rb', line 5 def initialize(command, serializer=nil) @serializer = serializer || SimpleSerializer.new run(command) end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/cod/process.rb', line 3 def pid @pid end |
Instance Method Details
#channel ⇒ Object
19 20 21 |
# File 'lib/cod/process.rb', line 19 def channel @pipe end |
#kill ⇒ Object
23 24 25 |
# File 'lib/cod/process.rb', line 23 def kill ::Process.kill :TERM, @pid end |
#run(command) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/cod/process.rb', line 11 def run(command) @pipe = Cod.bidir_pipe(@serializer) @pid = ::Process.spawn(command, :in => @pipe.w.r, :out => @pipe.r.w) end |
#terminate ⇒ Object
26 27 28 |
# File 'lib/cod/process.rb', line 26 def terminate @pipe.w.close end |
#wait ⇒ Object
30 31 32 |
# File 'lib/cod/process.rb', line 30 def wait ::Process.wait(@pid) end |