FIFO(4) BSD Programmer's Manual FIFO(4)NAMEfifo - named pipe
SYNOPSIS
options FIFO
DESCRIPTION
A fifo is a special file that conceptually acts like a pipe(2) with a
name. One process may open a fifo and write data to it, and another pro-
cess may open the same fifo and read that data out in the order that it
was written. Like pipes, fifos have flow control; that is, a writer will
block if it gets sufficiently ahead of its reader. Fifos provide a sim-
ple and convenient way for two unrelated processes to communicate.
A fifo file may be identified using stat(2). The S_ISFIFO macro tests a
file's mode bits and returns nonzero if the file is a fifo. The ls(1)
program displays fifo files in long format using the entry type character
`p'.
When a process tries to open a fifo special file, it may block, depending
on the state of the fifo. If the process tries to open a fifo for reading
and no process has opened or is trying to open the fifo for writing, and
the process's open(2) call does not specify O_NONBLOCK, the process will
block until some other process opens the file for writing, or until the
open(2) call is interrupted. A process that tries to open a fifo for
writing when no other process has opened or is trying to open the fifo
for reading will also block, unless the open(2) call uses the O_NONBLOCK
flag, in which case the open(2) call will return immediately with the er-
ror ENXIO. If a process tries to open a fifo for both reading and writ-
ing, the open(2) call will not block.
Once a fifo has been opened, it works much like a pipe; the read(2),
write(2), ioctl(2), select(2) and fpathconf(2) calls work on fifos as
they do on sockets and pipes. The pathconf(2) call works on fifos, pro-
viding the same results as fpathconf(2).
The kernel configuration option FIFO must be enabled in order for fifos
to work. If fifos are not configured, both mkfifo(2) and open(2) on a
fifo return -1 with errno set to EOPNOTSUPP.
STANDARDS
Fifos are described in IEEE Std1003.1-1988 (``POSIX'').
SEE ALSOmkfifo(1), mkfifo(2), pipe(2), socket(2)BSDI BSD/OS April 23, 1998 1