module Open4

def background arg, *argv

def background arg, *argv 
  require 'thread'
  q = Queue.new
  opts = { 'pid' => q, :pid => q }
  case argv.last
    when Hash
      argv.last.update opts
    else
      argv.push opts
  end
  thread = Thread.new(arg, argv){|_arg, _argv| spawn _arg, *_argv}
  sc = class << thread; self; end
  sc.module_eval {
    define_method(:pid){ @pid ||= q.pop }
    define_method(:spawn_status){ @spawn_status ||= value }
    define_method(:exitstatus){ @exitstatus ||= spawn_status.exitstatus }
  }
  thread
end