Checking if the other end of a fifo is open
Dave Smith
dave at thesmithfam.org
Thu Apr 9 18:04:00 MDT 2009
Frank Sorenson wrote:
> How about opening the fifo read/write, which doesn't block:
> # exec 4<> dave_fifo
> # ls -alF /proc/$$/fd
> ...
> lrwx------ 1 sorenson sorenson 64 2009-04-09 18:14 4 -> /tmp/dave_fifo|
>
> Here's an example script:
> #!/bin/bash
>
> exec 4<> /tmp/dave_fifo
> (sleep 2 ; kill -SIGUSR1 $$ ; echo "I'm alive" >&4) &
>
> # Wait for the flag to get raised, or give up after a while:
> read -t 5 -u 4 line
> if [ $? -eq 0 ] ; then
> echo "The child said: $line"
> else
> echo "Timed out waiting for child"
> fi
>
Interesting idea. Doesn't this block my daemon process (a separate piece
of C code) from opening the fifo for writing as well? My bash script
reads from the fifo, but the C program writes to it (and is responsible
for opening it for writing).
--Dave
More information about the PLUG
mailing list