Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening pipe with exec hangs

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?

like image 942
marmistrz Avatar asked May 27 '26 16:05

marmistrz


1 Answers

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.

like image 57
rici Avatar answered May 30 '26 05:05

rici