Note that there are some explanatory texts on larger screens.

plurals
  1. POBash Pipe Handling
    text
    copied!<p>Does anyone know how bash handles sending data through pipes?</p> <pre><code>cat file.txt | tail -20 </code></pre> <p>Does this command print all the contents of file.txt into a buffer, which is then read by tail? Or does this command, say, print the contents of file.txt line by line, and then pause at each line for tail to process, and then ask for more data? </p> <p>The reason I ask is that I'm writing a program on an embedded device that basically performs a sequence of operations on some chunk of data, where the output of one operation is send off as the input of the next operation. I would like to know how linux (bash) handles this so please give me a general answer, not specifically what happens when I run "cat file.txt | tail -20".</p> <p>Thank you in advance for your responses!</p> <p>EDIT: Shog9 pointed out a relevant Wikipedia Article, this didn't lead me directly to the article but it helped me find this: <a href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29#Implementation" rel="noreferrer">http://en.wikipedia.org/wiki/Pipeline_%28Unix%29#Implementation</a> which did have the information I was looking for.</p> <hr> <p>I'm sorry for not making myself clear. Of course you're using a pipe and of course you're using stdin and stdout of the respective parts of the command. I had assumed that was too obvious to state.</p> <p>What I'm asking is how this is handled/implemented. Since both programs cannot run at once, how is data sent from stdin to stdout? What happens if the first program generates data significantly faster than the second program? Does the system just run the first command until either it's terminated or it's stdout buffer is full, and then move on to the next program, and so on in a loop until no more data is left to be processed or is there a more complicated mechanism?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload