How do I use a named pipe?
To use the pipe, you open it like a normal file, and use read()
and write()
just as though it was a plain pipe.
However, the open()
of the pipe may block. The following rules
apply:
-
If you open for both reading and writing (O_RDWR
), then the open
will not block.
-
If you open for reading (O_RDONLY
), the open will block until
another process opens the FIFO for writing, unlessO_NONBLOCK
is
specified, in which case the open succeeds.
-
If you open for writingO_WRONLY
, the open will block until
another process opens the FIFO for reading, unlessO_NONBLOCK
is
specified, in which case the open fails.
When reading and writing the FIFO, the same considerations apply as for
regular pipes and sockets, i.e. read()
will return EOF when all
writers have closed, and write()
will raise SIGPIPE
when
there are no readers. If SIGPIPE
is blocked or ignored, the call
fails with EPIPE
.
Home | FAQ |