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 x
outputs the character 'x' and feeds it to cat1
which 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 pipe33a
and it has to wait.cat2 <pipe33b >pipe33a &
Reads the 'x' out of pipe33b
and writes it back out to pipe33a
pipe33a
and writes it back out to pipe33b
starting the whole process over again.