| Index: > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
|
|||||
An example of a pipeline, which should print the numbers from 1 to 13:
while : ; do echo ; done | head -n 13 | nl -ba
A "true" pipe is implemented by a shell on a multi-tasking operating system by launching both the source and the destination process at the same time, and servicing the data read requests by the destination process (on stdin) with the data that the source process writes to stdout.
Usually, read and write requests are blocking operations, which means that the execution of the source process, upon writing, is suspended until all data could be written to the destination process, and, likewise, the execution of the destination process, upon reading, is suspended until at least some of the requested data could be obtained from the source process. Obviously, this cannot lead to a deadlock, where both processes would wait indefinitely for each other to respond, since at least one of the two processes will soon thereafter have its request serviced by the operating system, and continue to run.
For performance, most operating systems implementing pipes use pipe bufferBuffer can have various meanings: In chemistry, the term buffer refers to a buffer solution, usually used to stabilize the acidity ( pH) of a liquid. In computing a buffer is a portion of memory set aside to store data, often before it is sent to an exters, which allow the source process to provide more data than the destination process is currently able or willing to receive. Under most Unices and Unix-like operating systems, a special command is also available which implements a pipe buffer of potentially much larger and configurable size, typically called "buffer". This command can be useful if the destination process is significantly slower than the source process, but it is anyway desired that the source process can complete its task as soon as possible. E.g., if the source process consists of a command which reads an audio track from a CD and the destination process consists of a command which compresses the waveformWaveform quite literally means the shape and form of a signal, such as a wave moving across the surface of water, or the vibration of a plucked string. In many cases the medium in which the wave is being propagated does not permit a direct visual image of audio data to a format like OGG Vorbis. In this case, buffering the entire track in a pipe buffer would allow the CD drive to spin down more quickly, and enable the user to remove the CD from the drive before the encoding process has finished. It should be noted that such a buffer command can be implemented using nothing but the already available operating system primitiveThe word primitive can refer to: primitive art and Primitivism (art) primitive (biology) primitive (computer science) primitive (linguistics) primitive (mathematics) primitive (ontology) Primitive (song).s for reading and writing data, however, to avoid wasteful active waiting , additional multithreading capabilities are desirable.
On single-tasking operating systems, such as MS-DOS, true pipes could not be implemented, since only one process could execute at a time. As a substitute, MS-DOS provided "pseudo-pipes" with the same syntax, but modified semantics. Upon entering a pipeline into the command line interpreterA command line interpreter is a computer program which reads a line of text the user has typed and interprets this text in the context of a given operating system or programming language. Command line interpreters have the advantage that the user may issu, COMMAND.COM, DOS would execute the commands one by one in sequential order, and, at each step, redirect their output and/or input to temporary files (with names implicitly assigned by MS-DOS). For instance, the command "dir | sort | more" would have been executed like this (albeit with more complicated temporary file names):
Thus, pseudo-pipes acted like true pipes with a pipe buffer of unlimited size (not withstanding disk space limitations), with the significant restriction that a receiving process could not read any data from the pipe buffer until the sending process finished completely. Besides causing disk traffic that would have been unnecessary under multi-tasking operating systems, this implementation also made pipes unsuitable for applications requiring real-time response, like, for example, interactive purposes (where the user enters commands that the first process in the pipeline receives via stdin, and the last process in the pipeline presents its output to the user via stdout).