diff options
Diffstat (limited to 'code/snippets/pipe_sharing_with_fork.rb')
| -rw-r--r-- | code/snippets/pipe_sharing_with_fork.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/code/snippets/pipe_sharing_with_fork.rb b/code/snippets/pipe_sharing_with_fork.rb new file mode 100644 index 0000000..038981a --- /dev/null +++ b/code/snippets/pipe_sharing_with_fork.rb @@ -0,0 +1,16 @@ +reader, writer = IO.pipe + +fork do + reader.close + + 10.times do + # heavy lifting + writer.puts "Another one bites the dust" + end +end + +writer.close +while message = reader.gets + $stdout.puts message +end + |
