The following code works, but if reader and writer are shared resource across parent and child process, why are they closed in the first place?
reader, writer = IO.pipe
fork do
reader.close
writer.puts "foobar"
end
writer.close
puts reader.read
This makes no sense to me, because I think the reader and writer should be closed after the write operation like the following code I made
reader, writer = IO.pipe
fork do
writer.puts "foobar"
writer.close
end
Process.wait
puts reader.read
reader.close
I don't know why it doesn't work. Can anyone give me an idea?