I have been reading about pipes in linux and I came across this in a book (http://linux-training.be/linuxsys.pdf, page 16)
First they create four pipes with mkfifo
$ mkfifo pipe33a pipe33b pipe42a pipe42b
$ cp /bin/cat proj33 && cp /bin/cat proj42
$ echo -n x | ./proj33 - pipe33a > pipe33b
$ ./proj33 <pipe33b >pipe33a &
The commands you see above will create two proj33 processes that use
cat to bounce the x character between pipe33a and pipe33b.
Explanation: Note for clarity I'm going to call the processes cat1 and cat2 rather than proj33.
echo -n xoutputs the character 'x' and feeds it to
cat1which is just a copy of the cat command.
cat1 - pipe33a > pipe33b: First reads stdin (that's what the
-means) and writes it to
pipe33b. Then cat1 tries to read from
pipe33aand it has to wait.
cat2 <pipe33b >pipe33a &Reads the 'x' out of
pipe33band writes it back out to
pipe33aand writes it back out to
pipe33bstarting the whole process over again.