#!/usr/bin/ruby -w puts "* one way child2parent pipe" rd, wr = IO.pipe if fork # parent wr.close puts "parent: got <#{rd.read}>" rd.close Process.wait else # child rd.close wr.write "hi parent" wr.close exit end puts "* two-way paren2child and child2parent pipe" parent2child_rd, parent2child_wr = IO.pipe child2parent_rd, child2parent_wr = IO.pipe if fork # parent child2parent_wr.close parent2child_wr.print "hi child" parent2child_wr.close puts "parent: got <#{child2parent_rd.read}>" child2parent_rd.close Process.wait else # child parent2child_wr.close puts "child: got <#{parent2child_rd.gets}>" parent2child_rd.close child2parent_wr.write "hi parent" child2parent_wr.close exit end print "parent exit\n"