Anonymous pipe

From Wikipedia, the free encyclopedia

In computer science, an anonymous pipe is a simplex FIFO communication channel that may be used for one-way interprocess communication. An implementation is often integrated into the operating system's file IO subsystem. Typically a parent program opens anonymous pipes, and creates a new process that inherits the other ends of the pipes, or creates several new processes and arranges them in a pipeline.

Two anonymous pipes are required for full-duplex (two-way) communication.

[edit] Microsoft Windows

Like many other device IO and IPC facilities in the Microsoft Windows Win32 API, anonymous pipes are created and configured with API functions specific to the IO facility. In this case CreatePipe is used to create an anonymous pipe with separate handles for the read and write ends of the pipe. Read and write IO operations on the pipe may use the standard IO facility API functions ReadFile and WriteFile.

On Microsoft Windows, reads and writes to anonymous pipes are always blocking. In other words, a read from an empty pipe will block in the call until either one or more bytes arrive, or the pipe is closed and an end-of-file is sent. Likewise, a write to a full pipe will block in the call until space becomes available to store the data being written. Reads may return with less than the number of bytes requested, otherwise known as a short-read.

New processes may inherit handles to anonymous pipes in the creation process. The new process simply needs a way of identifying the handle that it inherited.


Summary of anonymous pipes on Microsoft Windows:

  • Intramachine IPC only
  • Simplex (one-way)
  • Byte-oriented IO
  • Reliable
  • Read and write always blocking
  • Short-Read (successful reads may return less than the number of bytes requested) (Is also short-write?)
  • Standard device IO handles (FileRead, FileWrite)
  • Inheritable handles (CreateProcess)

[edit] See also

[edit] References

  • Hart, Johnson M. Windows System Programming, Third Edition. Addison-Wesley, 2005. ISBN 0-321-25619-0