Skip to content

Instantly share code, notes, and snippets.

@axgle
Forked from tansengming/forking_pipe.rb
Created October 14, 2009 11:15
Show Gist options
  • Save axgle/209990 to your computer and use it in GitHub Desktop.
Save axgle/209990 to your computer and use it in GitHub Desktop.
rd, wr = IO.pipe
if fork
wr.close
puts "Parent got: <#{rd.read}>"
rd.close
Process.wait
else
rd.close
puts "Sending message to parent"
wr.write "Hi Dad"
wr.close
end
# Produces
# Sending message to parent
# Parent got: <Hi Dad>
# From: http://www.ruby-doc.org/docs/rdoc/1.9/classes/IO.html#M001074
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment