nulogy/Gorgon

View on GitHub
lib/gorgon/pipe_forker.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Gorgon
  module PipeForker
    def pipe_fork
      stdin = Pipe.new(*IO.pipe)
      pid = fork do
        stdin.write.close
        STDIN.reopen(stdin.read)
        stdin.read.close

        yield

        exit
      end

      stdin.read.close

      return pid, stdin.write
    end

    private

    Pipe = Struct.new(:read, :write)
  end
end