Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Apr 20, 2018

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
You can’t perform that action at this time.