In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, an anonymous pipe is a
simplex FIFO communication channel that may be used for one-way
interprocess communication
In computer science, interprocess communication (IPC) is the sharing of data between running processes in a computer system. Mechanisms for IPC may be provided by an operating system. Applications which use IPC are often categorized as clients ...
(IPC). An implementation is often integrated into the
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
'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
A pipeline is a system of Pipe (fluid conveyance), pipes for long-distance transportation of a liquid or gas, typically to a market area for consumption. The latest data from 2014 gives a total of slightly less than of pipeline in 120 countries ...
.
Full-duplex (two-way) communication normally requires two anonymous pipes.
Pipelines are supported in most popular operating systems, from
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
DOS onwards, and are created using the "
,
" character in many shells.
Unix
Pipelines are an important part of many traditional
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
applications and support for them is well integrated into most
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems. Pipes are created using the
pipe
system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
, which creates a new pipe and returns a pair of
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically h ...
s referring to the read and write ends of the pipe. Many traditional Unix programs are designed as
filters
Filtration is a physical process that separates solid matter and fluid from a mixture.
Filter, filtering, filters or filtration may also refer to:
Science and technology
Computing
* Filter (higher-order function), in functional programming
* Fil ...
to work with pipes.
Microsoft Windows
Like many other device IO and IPC facilities in the
Windows API
The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs can acces ...
, anonymous pipes are created and configured with API functions that are 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 are performed with the standard IO facility API functions
ReadFile
and
WriteFile
.
On
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
, reads and writes to anonymous pipes are always blocking.
In other words, a read from an empty pipe will cause the calling thread to wait until at least one byte becomes available or an
end-of-file is received as a result of the write handle of the pipe being closed. Likewise, a write to a full pipe will cause the calling thread to wait until space becomes available to store the data being written. Reads may return with fewer than the number of bytes requested (also called a ''short read'').
New processes can inherit handles to anonymous pipes in the creation process.
See also
*
Named pipe
*
Anonymous named pipe
*
Pipeline (Unix)
In Unix-like computer operating systems, a pipeline is a mechanism for inter-process communication using message passing. A pipeline is a set of process (computing), processes chained together by their standard streams, so that the output text of ...
References
* Hart, Johnson M. ''Windows System Programming, Third Edition.'' Addison-Wesley, 2005.
*
Notes
{{Inter-process communication
Inter-process communication