Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Tesing a fifo without opening it?



I'm writing a multi process scripting system in zsh:

---- main script
mkfifo in1
mkdifo out1
(sub-script in1 out1)&
echo command > in1
read ANSWER < out1

mkfifo in2
mkdifo out2
(sub-script in2 out2)&
echo command > in1
read ANSWER < out1

...
----

---- sub script
read REQUEST < "$1"
echo answer > "$2"
# do something
----

So far, this works very well.  Note that reading from an writing to the pipes blocks (in the open() call) until the other end has also opened the pipe.  Also note that the main script may start many concurrent sub scripts and communicate with them through many different fifos.

Now I want to improve the scripts so that the main script can send the string "exit" to the sub scripts at any time and the sub script then exits:

---- main script
...
echo exit > in1
read ANSWER < out1
echo exit > in2
read ANSWER < out1
----

---- sub script
01 read REQUEST < "$1"
02 echo answer > "$2"
03 # do something
04 while true; do
05   if read -t REQUEST < "$1"; then
06     echo answer > $2
07     test x"$REQUEST" = xexit && exit
08   else
09     # do something else
10     ...
11   fi
12 done
----

Now, the problem is that input redirection in line 5 blocks until the main script also opens the fifo.  So the -t flag of read does not "work" here (because read is not even executed until the fifo can be opened).  I want to check if data is available in the fifo without blocking, but I can't find a way around blocking in the input redirection.

Ciao

Dominik ^_^  ^_^
-- 
Achtung Sicherheitswarnung: GMX warnt vor Phishing-Attacken!
http://portal.gmx.net/de/go/sicherheitspaket



Messages sorted by: Reverse Date, Date, Thread, Author