Skip to content

Instantly share code, notes, and snippets.

@elight
Created September 11, 2010 02:06
Show Gist options
  • Save elight/574685 to your computer and use it in GitHub Desktop.
Save elight/574685 to your computer and use it in GitHub Desktop.
def fork_tourist
fork do
# we're in the child
# run your tour
end
end
number_of_tours = 20
pipes = []
number_of_tours.times do |idx|
pipe.read, pipe.write = IO.pipe
pipes << [idx, pipe.read, pipe.write]
end
pipes.each do |pipe|
fork_tourist
end
MAX_LEN = 1024
# we're in the parent
while true
pipes.each do |id, pipe_read, _|
result = read_pipe.read_nonblock(MAX_LEN)
case result
...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment