I want to open a file descriptor only for reading
mkfifo my_fifo
exec 3<$my_fifo
This one hangs.
On the other hand when I do
exec 3<>$my_fifo
Then it works. Why?
Opening a fifo (named pipe) for reading hangs until some process has the fifo open for writing, and vice versa. So when the open returns, you know the "other end" of the pipe is open.
Linux allows you to open a pipe in both directions. If you do that, both ends of the pipe are open, so the open returns immediately. This is an extension to Posix and will not work on all systems.
man 7 fifo has more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With