다음을 통해 공유


Some History of the Named Pipe, Part 2

The anonymous pipes that I talked about last time satisfy the basic requirements of an inter-process communication mechanism but have the considerable drawback of only working between two processes that share a parent-child relationship. The need for inter-process communication between two unrelated processes is reflected in another mechanism called a fifo (also sometimes called a named pipe).

A fifo is in many ways similar to a pipe on the surface but the two are different entities. Like a pipe, a fifo supports unidirectional communication from a writer to a reader. Unlike a pipe though, a fifo shares several characteristics with file-based devices, such as a name and an entry in the file system. A pipe is opened through the act of creating it while a fifo is first created and then opened for reading and writing by other processes.

The similarity between a fifo and a file device is actually substantial. In fact, the standard Unix system call for creating a fifo is int mknod (char *pathname, int mode, int device), which is the same system call for creating other kinds of devices. Creating most other devices requires special privileges though while ordinary users can create a fifo. A fifo is distinguished by the use of a particular flag bit in the mode, allowing the two uses to exist side by side. The pathname is what gives the name to the named pipe.

Once created, the fifo can be opened like an ordinary file, and after that can be read, written, or closed just like any pipe.

The Windows named pipe isn’t precisely the same as a fifo though, and those differences are what I’ll talk about next time.