Totally new to pipes, but an avid reader and wouldn't care to waste your original effort.
Code:
#!/bin/bash
mkfifo fifo_one
mkfifo fifo_two
# create infinite input to fifos for illustration...
yes |sed 's/y/this is one/' | nl > fifo_one &
yes |sed 's/y/this is two/' | nl > fifo_two &
n=1
while [ $n -le 3 ]; do
read -u 3 one_data
read -u 4 two_data
echo "$n from fifo_one: \"$one_data\"; from fifo_two: \"$two_data\""
let n+=1
done 3< fifo_one 4< fifo_two
# kill backgrounded processes
kill -9 %1
kill -9 %2
# wait will they're dead
wait
# clean up fifos
rm -f fifo_one fifo_two
I am unsure why I should get the error messages from the kills.
Quote:
1 from fifo_one: "1 this is one"; from fifo_two: "1 this is two"
2 from fifo_one: "2 this is one"; from fifo_two: "2 this is two"
3 from fifo_one: "3 this is one"; from fifo_two: "3 this is two"
./pipesh: line 21: kill: %1: no such job
./pipesh: line 22: kill: %2: no such job
|
I did put a couple of sleeps into the code and hit it with a deft couple of ^C^C and re-ran the code to get
Quote:
mkfifo: cannot create fifo `fifo_one': File exists
mkfifo: cannot create fifo `fifo_two': File exists
1 from fifo_one: "1 this is one"; from fifo_two: "1 this is two"
. . .
|
This did at least confirms to me that the kills had been working correctly, despite the error messages which caused me some small doubts, and the original pipes seemed to be re-used when it wasn't able to create them anew due to my intervention. Subsequently of course, keeping my fingers out, the runs were clean other than for the unexplained kill error messages.
You might take some comfort from the fact that this is probably going to take me a couple of hours at least to get my mind around fully. I know that I could always re-direct std error to /dev/null, but I would prefer to understand it before rashly sweeping trouble under the carpet.
Having once sorted it all out in my mind, I'll be looking to see where I might naturally use named pipes to advantage. Oh, and I shall be consulting our friend Google also.
Thanks

+

=
