https://de.wikipedia.org/w/api.php?action=feedcontributions&feedformat=atom&user=Slugger Wikipedia - Benutzerbeiträge [de] 2025-06-02T05:29:48Z Benutzerbeiträge MediaWiki 1.45.0-wmf.3 https://de.wikipedia.org/w/index.php?title=Pipeline_(Unix)&diff=180301441 Pipeline (Unix) 2007-02-18T23:43:36Z <p>Slugger: Reverted edits by 201.243.38.17 (talk) using Mike&#039;s Wiki Tool 0.9.2</p> <hr /> <div>[[Image:Pipeline.svg|thumb|A pipeline of three programs run on a text terminal]]<br /> In [[Unix-like]] computer [[operating system]]s, a '''pipeline''' is the original ''[[pipeline (software)|software pipeline]]'': a set of [[process (computing)|process]]es chained by their [[standard streams]], so that the output of each process (''[[stdout]]'') feeds directly as input (''[[stdin]]'') of the next one. Each connection is implemented by an [[anonymous pipe]]. [[Filter (Unix)|Filter program]]s are often used in this configuration. The concept was invented by [[Douglas McIlroy]] for [[Unix shell]]s and it was named by analogy to a physical [[pipeline transport|pipeline]].<br /> <br /> ==Example==<br /> <br /> Below is an example of a pipeline that implements a kind of [[spell checker]] for the [[World Wide Web|web]] resource indicated by a [[Uniform Resource Locator|URL]]. An explanation of what it does follows. (Some machines have /usr/share/dict/words instead.)<br /> <br /> [[CURL|curl]] &lt;nowiki&gt;&quot;http://en.wikipedia.org/wiki/Pipeline_(Unix)&quot;&lt;/nowiki&gt; | \<br /> [[sed]] 's/[^a-zA-Z ]/ /g' | \<br /> [[tr (program)|tr]] 'A-Z ' 'a-z\n' | \<br /> [[grep]] '[a-z]' | \<br /> [[Sort (Unix)|sort]] -u | \<br /> [[comm (Unix)|comm]] -23 - /usr/dict/words<br /> <br /> *First, '''&lt;tt&gt;curl&lt;/tt&gt;''' obtains the [[HTML]] contents of a web page.<br /> *Second, '''&lt;tt&gt;sed&lt;/tt&gt;''' removes all characters which are not spaces or letters from the web page's content, replacing them with spaces.<br /> *Third, '''&lt;tt&gt;tr&lt;/tt&gt;''' changes all of the uppercase letters into lowercase and converts the spaces in the lines of text to newlines (each 'word' is now on a separate line).<br /> *Fourth, '''&lt;tt&gt;grep&lt;/tt&gt;''' removes lines of [[whitespace]].<br /> *Fifth, '''&lt;tt&gt;sort&lt;/tt&gt;''' sorts the list of 'words' into alphabetical order, and removes duplicates.<br /> *Finally, '''&lt;tt&gt;comm&lt;/tt&gt;''' finds which of the words in the list are not in the given dictionary file (in this case, /usr/dict/words).<br /> <br /> == Pipelines in command line interfaces ==<br /> Most [[Unix shell]]s have a special syntax construct for the creation of pipelines. Typically, one simply writes the filter commands in sequence, separated by the [[ASCII]] [[vertical bar]] character &quot;|&quot; (which, for this reason, is often called &quot;pipe character&quot; by Unix users). The shell starts the processes and arranges for the necessary connections between their standard streams (including some amount of [[Buffer (computer science)|buffer]] storage). &lt;!-- Shouldn't this be in the shell article? As with all shell commands, a command line can be extended over multiple physical lines by using a '\' character before the newline. --&gt;<br /> <br /> ===Error stream===<br /> By default, the standard error streams (&quot;[[stderr]]&quot;) of the processes in a pipeline are not passed on through the pipe; instead, they are merged and directed to the [[computer console|console]]. However, many shells have additional syntax for changing this behaviour. In the [[C shell|csh]] shell, for instance, using &quot;|&amp;&quot; instead of &quot;| &quot; signifies that the [[standard error]] stream too should be merged with the standard output and fed to the next process. The [[Bourne Shell]] can also merge standard error, as well as redirect it to a different file.<br /> <br /> ==Creating pipelines programmatically==<br /> <br /> Pipelines can be created under program control.<br /> The &lt;code&gt;pipe()&lt;/code&gt; [[system call]] asks the operating system to construct a new [[anonymous pipe]] object.<br /> This results in two new, opened file descriptors in the process: the read-only end of the pipe, and the write-only end.<br /> The pipe ends appear to be normal, anonymous [[file descriptor]]s, except that they have no ability to seek.<br /> <br /> To avoid [[deadlock]] and exploit parallelism, the process with one or more new pipes will then, generally, call<br /> &lt;code&gt;[[fork (computing)|fork()]]&lt;/code&gt; to create new<br /> processes. Each process will then close the end(s) of<br /> the pipe that it will not be using before producing or consuming any data.<br /> Alternatively, a process might create a new [[pthreads|thread]] and use the pipe to communicate between them.<br /> <br /> ''[[Named pipe]]s'' may also be created using &lt;code&gt;mkfifo()&lt;/code&gt; or &lt;code&gt;mknod()&lt;/code&gt; and then presented as the input or output file to programs as they are invoked. They allow multi-path pipes to be created, and are especially effective when combined with standard error redirection, or with [[tee (Unix)|tee]].<br /> <br /> ==Implementation==<br /> <br /> In most Unix-like systems, all processes of a pipeline are started at the same time, with their streams appropriately connected&lt;!--details please: buffering--&gt;, and managed by the [[scheduler]] together with all other processes running on the machine. &lt;!--death of a process, broken pipes, signal handling, etc.--&gt; An important aspect of this, setting Unix pipes apart from other pipe implementations, is the concept of [[Buffer (computer science)|buffering]]: a sending program may produce 5000 [[bytes]] per [[second]], and a receiving program may only be able to accept 100 bytes per second, but no data are lost. Instead, the output of the sending program is held in a buffer, or [[Queue (data structure)|queue]]. When the receiving program is ready to read data, the operating system sends it data from the buffer, then removes that data from the buffer. If the buffer fills up, the sending program is suspended (blocked) until the receiving program has had a chance to read some data and make room in the buffer.<br /> <br /> === Network pipes ===<br /> Tools like [[netcat]] and [[socat]] can connect pipes to TCP/IP [[socket]]s, following the Unix philosophy of &quot;[[everything is a file]]&quot;.<br /> <br /> == History==<br /> [[Image: Automator_Icon.png|thumb|75px|right|Apple Automator logo]] <br /> The pipeline concept and the vertical-bar notation was invented by [[Douglas McIlroy]], one of the authors of the early [[Unix shell|command shells]], after he noticed that much of the time they were processing the output of one program as the input to another. The idea was eventually ported to other operating systems, such as [[DOS]], [[OS/2]], [[Windows NT]], and [[BeOS]] often with the same notation. <br /> <br /> The robot in the icon for [[Apple Computer|Apple]]'s [[Automator (software)|Automator]], which also uses pipeline concept to chain repetitive commands together, holds a pipe as recognition of the application's Unix heritage.&lt;ref name=&quot;automator&quot;/&gt;<br /> <br /> === Other operating systems ===<br /> {{main|pipeline (software)}}<br /> <br /> This feature of [[Unix]] was borrowed by other operating systems, such as [[Taos operating system|Taos]] and [[MS-DOS]], and eventually became the [[pipeline (software)|pipes and filters design pattern]] of [[software engineering]]. <br /> <br /> == See also ==<br /> * [[Tee (Unix)]] for fitting together two pipes<br /> * [[Pipeline (software)]] for the general software engineering concept.<br /> * [[Pipeline (computer)]] for other computer-related pipelines.<br /> * [[Hartmann pipeline]]<br /> * [[Anonymous pipe]] a [[FIFO]] structure used for [[interprocess communication]]<br /> * [[Named pipe]] persistent pipes used for interprocess communication<br /> * [[XML pipeline]] for processing of XML files<br /> <br /> ==External links==<br /> *[http://en.wikibooks.org/w/index.php?title=Ad_Hoc_Data_Analysis_From_The_Unix_Command_Line ''Ad Hoc Data Analysis From The Unix Command Line'' at Wikibooks] shows how to use pipelines composed of simple filters to do complex data analysis.<br /> *[http://www.pixelbeat.org/programming/stdio_buffering/ stdio buffering]<br /> <br /> ==References==<br /> * [[Sal Soghoian]] on [[MacBreak]] Episode 5 &quot;Enter the Automatrix&quot;<br /> <br /> [[Category:Inter-process communication]]<br /> [[Category:Unix]]<br /> <br /> [[it:Pipeline (Unix)]]<br /> [[ja:パイプ (コンピュータ)]]<br /> [[pt:Pipeline (Unix)]]<br /> [[zh:Pipe]]</div> Slugger