Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created September 1, 2013 18:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/6406361 to your computer and use it in GitHub Desktop.
Save thinkerbot/6406361 to your computer and use it in GitHub Desktop.
Demonstrates that multiple writers to a single fifo often get inputs interleaved, regardless of sync.
#!/bin/bash
# 8... always?
mkfifo fifo
ruby -e '100000.times {|i| puts "a"}' > fifo &
ruby -e '100000.times {|i| puts "b"}' > fifo &
ruby -e '100000.times {|i| puts "c"}' > fifo &
ruby -e '100000.times {|i| puts "d"}' > fifo &
ruby -e '100000.times {|i| puts "e"}' > fifo &
ruby -e '100000.times {|i| puts "f"}' > fifo &
ruby -e '100000.times {|i| puts "g"}' > fifo &
ruby -e '100000.times {|i| puts "h"}' > fifo &
ruby -e '
counts = Hash.new(0)
while line = gets
counts[line.chomp("\n")] += 1
end
puts counts.length
' < fifo
rm fifo
#!/bin/bash
# > 8
mkfifo fifo
ruby -e '1000.times {|i| puts("a" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("b" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("c" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("d" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("e" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("f" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("g" * 1000)}' > fifo &
ruby -e '1000.times {|i| puts("h" * 1000)}' > fifo &
ruby -e '
counts = Hash.new(0)
while line = gets
counts[line.chomp("\n")] += 1
end
puts counts.length
' < fifo
rm fifo
#!/bin/bash
# > 8
mkfifo fifo
ruby -e '$stdout.sync = true; 100000.times {|i| puts "a"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "b"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "c"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "d"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "e"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "f"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "g"}' > fifo &
ruby -e '$stdout.sync = true; 100000.times {|i| puts "h"}' > fifo &
ruby -e '
counts = Hash.new(0)
while line = gets
counts[line.chomp("\n")] += 1
end
puts counts.length
' < fifo
rm fifo
@ORESoftware
Copy link

thanks, this is what I suspected...looking for answers here:

https://stackoverflow.com/questions/49937798/how-to-multiplex-named-pipe-fifo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment