Understanding piped commands in Unix/LinuxHow big is the pipe buffer?In what order do piped commands run?In what order do piped commands run?How a piped shell programs balance their output/input rates?Understanding behavior of subshell and stdout with pipeUnderstanding i/o redirection in the context of _process substitution_“Leaky” pipes in linuxCan writing to stdout place backpressure on a process?How to send variable value to pipe while hiding it from the process list?Take a command that modifies a file inline and make it accept stdin/stdoutCommunicate backwards in a pipeWhy doesn't grep remove lines of terminal output from find command by default?

My ID is expired, can I fly to the Bahamas with my passport

Is thermodynamics only applicable to systems in equilibrium?

Can PCs use nonmagical armor and weapons looted from monsters?

I caught several of my students plagiarizing. Could it be my fault as a teacher?

How to creep the reader out with what seems like a normal person?

Was Unix ever a single-user OS?

Write to EXCEL from SQL DB using VBA script

You look catfish vs You look like a catfish?

Can a cyclic Amine form an Amide?

Field Length Validation for Desktop Application which has maximum 1000 characters

How did Captain America use this power?

What happened to Rhaegal?

How to efficiently calculate prefix sum of frequencies of characters in a string?

How do you center multiple equations that have multiple steps?

If 1. e4 c6 is considered as a sound defense for black, why is 1. c3 so rare?

Is lying to get "gardening leave" fraud?

If Melisandre foresaw another character closing blue eyes, why did she follow Stannis?

What happened to Ghost?

Why is this a valid proof for the harmonic series?

If an enemy is just below a 10-foot-high ceiling, are they in melee range of a creature on the ground?

Why is Thanos so tough at the beginning of "Avengers: Endgame"?

How did Arya get back her dagger from Sansa?

Airbnb - host wants to reduce rooms, can we get refund?

A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours



Understanding piped commands in Unix/Linux


How big is the pipe buffer?In what order do piped commands run?In what order do piped commands run?How a piped shell programs balance their output/input rates?Understanding behavior of subshell and stdout with pipeUnderstanding i/o redirection in the context of _process substitution_“Leaky” pipes in linuxCan writing to stdout place backpressure on a process?How to send variable value to pipe while hiding it from the process list?Take a command that modifies a file inline and make it accept stdin/stdoutCommunicate backwards in a pipeWhy doesn't grep remove lines of terminal output from find command by default?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








16















I have two simple programs: A and B. A would run first, then B gets the “stdout” of A and uses it as its “stdin”. Assume I am using a GNU/Linux operating system and the simplest possible way to do this would be:



./A | ./B


If I had to describe this command, I would say that it is a command that takes input (i.e., reads) from a producer (A) and writes to a consumer (B). Is that a correct description? Am I missing anything?










share|improve this question
























  • Related: In what order do piped commands run?

    – G-Man
    Apr 21 at 21:35











  • It's not command, it's an kenerl object created by bash process, which is used as stdout of process A and stdin as B. Two processes are started nearly at the same time.

    – 炸鱼薯条德里克
    Apr 22 at 0:45






  • 1





    @炸鱼 You're correct - for kernel pipeline is an object in pipefs filesystem, but as far as shell itself is concerned - technically that's a pipeline command

    – Sergiy Kolodyazhnyy
    Apr 22 at 1:30

















16















I have two simple programs: A and B. A would run first, then B gets the “stdout” of A and uses it as its “stdin”. Assume I am using a GNU/Linux operating system and the simplest possible way to do this would be:



./A | ./B


If I had to describe this command, I would say that it is a command that takes input (i.e., reads) from a producer (A) and writes to a consumer (B). Is that a correct description? Am I missing anything?










share|improve this question
























  • Related: In what order do piped commands run?

    – G-Man
    Apr 21 at 21:35











  • It's not command, it's an kenerl object created by bash process, which is used as stdout of process A and stdin as B. Two processes are started nearly at the same time.

    – 炸鱼薯条德里克
    Apr 22 at 0:45






  • 1





    @炸鱼 You're correct - for kernel pipeline is an object in pipefs filesystem, but as far as shell itself is concerned - technically that's a pipeline command

    – Sergiy Kolodyazhnyy
    Apr 22 at 1:30













16












16








16


3






I have two simple programs: A and B. A would run first, then B gets the “stdout” of A and uses it as its “stdin”. Assume I am using a GNU/Linux operating system and the simplest possible way to do this would be:



./A | ./B


If I had to describe this command, I would say that it is a command that takes input (i.e., reads) from a producer (A) and writes to a consumer (B). Is that a correct description? Am I missing anything?










share|improve this question
















I have two simple programs: A and B. A would run first, then B gets the “stdout” of A and uses it as its “stdin”. Assume I am using a GNU/Linux operating system and the simplest possible way to do this would be:



./A | ./B


If I had to describe this command, I would say that it is a command that takes input (i.e., reads) from a producer (A) and writes to a consumer (B). Is that a correct description? Am I missing anything?







pipe terminology






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 22 at 17:15









G-Man

13.9k93870




13.9k93870










asked Apr 21 at 11:59









nihulusnihulus

1865




1865












  • Related: In what order do piped commands run?

    – G-Man
    Apr 21 at 21:35











  • It's not command, it's an kenerl object created by bash process, which is used as stdout of process A and stdin as B. Two processes are started nearly at the same time.

    – 炸鱼薯条德里克
    Apr 22 at 0:45






  • 1





    @炸鱼 You're correct - for kernel pipeline is an object in pipefs filesystem, but as far as shell itself is concerned - technically that's a pipeline command

    – Sergiy Kolodyazhnyy
    Apr 22 at 1:30

















  • Related: In what order do piped commands run?

    – G-Man
    Apr 21 at 21:35











  • It's not command, it's an kenerl object created by bash process, which is used as stdout of process A and stdin as B. Two processes are started nearly at the same time.

    – 炸鱼薯条德里克
    Apr 22 at 0:45






  • 1





    @炸鱼 You're correct - for kernel pipeline is an object in pipefs filesystem, but as far as shell itself is concerned - technically that's a pipeline command

    – Sergiy Kolodyazhnyy
    Apr 22 at 1:30
















Related: In what order do piped commands run?

– G-Man
Apr 21 at 21:35





Related: In what order do piped commands run?

– G-Man
Apr 21 at 21:35













It's not command, it's an kenerl object created by bash process, which is used as stdout of process A and stdin as B. Two processes are started nearly at the same time.

– 炸鱼薯条德里克
Apr 22 at 0:45





It's not command, it's an kenerl object created by bash process, which is used as stdout of process A and stdin as B. Two processes are started nearly at the same time.

– 炸鱼薯条德里克
Apr 22 at 0:45




1




1





@炸鱼 You're correct - for kernel pipeline is an object in pipefs filesystem, but as far as shell itself is concerned - technically that's a pipeline command

– Sergiy Kolodyazhnyy
Apr 22 at 1:30





@炸鱼 You're correct - for kernel pipeline is an object in pipefs filesystem, but as far as shell itself is concerned - technically that's a pipeline command

– Sergiy Kolodyazhnyy
Apr 22 at 1:30










2 Answers
2






active

oldest

votes


















26














The only thing about your question that stands out as wrong is that you say




A would run first, then B gets the stdout of A




In fact, both programs would be started at pretty much the same time. If there's no input for B when it tries to read, it will block until there is input to read. Likewise, if there's nobody reading the output from A, its writes will block until its output is read (some of it will be buffered by the pipe).



The only thing synchronising the processes that take part in a pipeline is the I/O, i.e. the reading and writing. If no writing or reading happens, then the two processes will run totally independent of each other. If one ignores the reading or writing of the other, the ignored process will block and eventually be killed by a SIGPIPE signal (if writing) or get an end-of-file condition on its standard input stream (if reading) when the other process terminates.



The idiomatic way to describe A | B is that it's a pipeline containing two programs. The output produced on standard output from the first program is available to be read on the standard input by the second ("[the output of] A is piped into B"). The shell does the required plumbing to allow this to happen.



If you want to use the words "consumer" and "producer", I suppose that's ok too.



The fact that these are programs written in C is not relevant. The fact that this is Linux, macOS, OpenBSD or AIX is not relevant.






share|improve this answer




















  • 2





    Writing to a temporary file was used in DOS, as that didn't support multiple processes.

    – CSM
    Apr 21 at 17:56






  • 2





    @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

    – Kusalananda
    Apr 21 at 17:58






  • 2





    @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

    – Michael Homer
    Apr 21 at 21:41







  • 6





    @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

    – Uncle Billy
    Apr 21 at 22:29







  • 1





    @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

    – Alex Vong
    Apr 21 at 23:53



















2














The term usually used in documentation is "pipeline" , which consists of one or more commands, see POSIX definition So technically speaking, that's two commands you have there, two subprocesses for the shell (either fork()+exec()'ed external commands or subshells )



As for producer-consumer part, the pipeline can be described by that pattern, since:



  • Producer and Consumer share fixed-size buffer, and at least on Linux and MacOS X, there's fixed size for pipeline buffer

  • Producer and Consumer are loosely-coupled, commands in pipeline don't know of each other's existence ( unless they are actively checking /proc/<pid>/fd directory ).

  • Producers write to stdout and consumers read stdin as if they were a single command being executed, aka they can exist without each other.

The difference I see here is that unlike Producer-Consumer in other languges, shell commands use buffering and they write stdout once buffer is filled, but there's no mention that Producer-Consumer has to follow that rule - only wait when queue is filled or discard data (which is something else that pipeline doesn't do).






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513657%2funderstanding-piped-commands-in-unix-linux%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    26














    The only thing about your question that stands out as wrong is that you say




    A would run first, then B gets the stdout of A




    In fact, both programs would be started at pretty much the same time. If there's no input for B when it tries to read, it will block until there is input to read. Likewise, if there's nobody reading the output from A, its writes will block until its output is read (some of it will be buffered by the pipe).



    The only thing synchronising the processes that take part in a pipeline is the I/O, i.e. the reading and writing. If no writing or reading happens, then the two processes will run totally independent of each other. If one ignores the reading or writing of the other, the ignored process will block and eventually be killed by a SIGPIPE signal (if writing) or get an end-of-file condition on its standard input stream (if reading) when the other process terminates.



    The idiomatic way to describe A | B is that it's a pipeline containing two programs. The output produced on standard output from the first program is available to be read on the standard input by the second ("[the output of] A is piped into B"). The shell does the required plumbing to allow this to happen.



    If you want to use the words "consumer" and "producer", I suppose that's ok too.



    The fact that these are programs written in C is not relevant. The fact that this is Linux, macOS, OpenBSD or AIX is not relevant.






    share|improve this answer




















    • 2





      Writing to a temporary file was used in DOS, as that didn't support multiple processes.

      – CSM
      Apr 21 at 17:56






    • 2





      @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

      – Kusalananda
      Apr 21 at 17:58






    • 2





      @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

      – Michael Homer
      Apr 21 at 21:41







    • 6





      @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

      – Uncle Billy
      Apr 21 at 22:29







    • 1





      @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

      – Alex Vong
      Apr 21 at 23:53
















    26














    The only thing about your question that stands out as wrong is that you say




    A would run first, then B gets the stdout of A




    In fact, both programs would be started at pretty much the same time. If there's no input for B when it tries to read, it will block until there is input to read. Likewise, if there's nobody reading the output from A, its writes will block until its output is read (some of it will be buffered by the pipe).



    The only thing synchronising the processes that take part in a pipeline is the I/O, i.e. the reading and writing. If no writing or reading happens, then the two processes will run totally independent of each other. If one ignores the reading or writing of the other, the ignored process will block and eventually be killed by a SIGPIPE signal (if writing) or get an end-of-file condition on its standard input stream (if reading) when the other process terminates.



    The idiomatic way to describe A | B is that it's a pipeline containing two programs. The output produced on standard output from the first program is available to be read on the standard input by the second ("[the output of] A is piped into B"). The shell does the required plumbing to allow this to happen.



    If you want to use the words "consumer" and "producer", I suppose that's ok too.



    The fact that these are programs written in C is not relevant. The fact that this is Linux, macOS, OpenBSD or AIX is not relevant.






    share|improve this answer




















    • 2





      Writing to a temporary file was used in DOS, as that didn't support multiple processes.

      – CSM
      Apr 21 at 17:56






    • 2





      @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

      – Kusalananda
      Apr 21 at 17:58






    • 2





      @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

      – Michael Homer
      Apr 21 at 21:41







    • 6





      @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

      – Uncle Billy
      Apr 21 at 22:29







    • 1





      @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

      – Alex Vong
      Apr 21 at 23:53














    26












    26








    26







    The only thing about your question that stands out as wrong is that you say




    A would run first, then B gets the stdout of A




    In fact, both programs would be started at pretty much the same time. If there's no input for B when it tries to read, it will block until there is input to read. Likewise, if there's nobody reading the output from A, its writes will block until its output is read (some of it will be buffered by the pipe).



    The only thing synchronising the processes that take part in a pipeline is the I/O, i.e. the reading and writing. If no writing or reading happens, then the two processes will run totally independent of each other. If one ignores the reading or writing of the other, the ignored process will block and eventually be killed by a SIGPIPE signal (if writing) or get an end-of-file condition on its standard input stream (if reading) when the other process terminates.



    The idiomatic way to describe A | B is that it's a pipeline containing two programs. The output produced on standard output from the first program is available to be read on the standard input by the second ("[the output of] A is piped into B"). The shell does the required plumbing to allow this to happen.



    If you want to use the words "consumer" and "producer", I suppose that's ok too.



    The fact that these are programs written in C is not relevant. The fact that this is Linux, macOS, OpenBSD or AIX is not relevant.






    share|improve this answer















    The only thing about your question that stands out as wrong is that you say




    A would run first, then B gets the stdout of A




    In fact, both programs would be started at pretty much the same time. If there's no input for B when it tries to read, it will block until there is input to read. Likewise, if there's nobody reading the output from A, its writes will block until its output is read (some of it will be buffered by the pipe).



    The only thing synchronising the processes that take part in a pipeline is the I/O, i.e. the reading and writing. If no writing or reading happens, then the two processes will run totally independent of each other. If one ignores the reading or writing of the other, the ignored process will block and eventually be killed by a SIGPIPE signal (if writing) or get an end-of-file condition on its standard input stream (if reading) when the other process terminates.



    The idiomatic way to describe A | B is that it's a pipeline containing two programs. The output produced on standard output from the first program is available to be read on the standard input by the second ("[the output of] A is piped into B"). The shell does the required plumbing to allow this to happen.



    If you want to use the words "consumer" and "producer", I suppose that's ok too.



    The fact that these are programs written in C is not relevant. The fact that this is Linux, macOS, OpenBSD or AIX is not relevant.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 21 at 22:03

























    answered Apr 21 at 12:26









    KusalanandaKusalananda

    144k18272450




    144k18272450







    • 2





      Writing to a temporary file was used in DOS, as that didn't support multiple processes.

      – CSM
      Apr 21 at 17:56






    • 2





      @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

      – Kusalananda
      Apr 21 at 17:58






    • 2





      @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

      – Michael Homer
      Apr 21 at 21:41







    • 6





      @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

      – Uncle Billy
      Apr 21 at 22:29







    • 1





      @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

      – Alex Vong
      Apr 21 at 23:53













    • 2





      Writing to a temporary file was used in DOS, as that didn't support multiple processes.

      – CSM
      Apr 21 at 17:56






    • 2





      @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

      – Kusalananda
      Apr 21 at 17:58






    • 2





      @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

      – Michael Homer
      Apr 21 at 21:41







    • 6





      @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

      – Uncle Billy
      Apr 21 at 22:29







    • 1





      @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

      – Alex Vong
      Apr 21 at 23:53








    2




    2





    Writing to a temporary file was used in DOS, as that didn't support multiple processes.

    – CSM
    Apr 21 at 17:56





    Writing to a temporary file was used in DOS, as that didn't support multiple processes.

    – CSM
    Apr 21 at 17:56




    2




    2





    @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

    – Kusalananda
    Apr 21 at 17:58





    @AlexVong Note though that your example with a temporary file is not exactly equivalent. A program may choose to seek though the contents of a file, but data coming off a pipe is not seekable. A better examlp would be to use mkfifo to create a named pipe, then start B in the background reading from the pipe, and then A writing to it. This is nit-picking though, as the effect would be the same.

    – Kusalananda
    Apr 21 at 17:58




    2




    2





    @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

    – Michael Homer
    Apr 21 at 21:41






    @AlexVong The simplifications made in that article divorce it from real pipelines; the parallel execution is truly semantic, not an optimisation. It's a reasonable lies-to-children explanation of monadic evaluation or composition for someone who's seen shell pipelines, but it's not valid in the other direction. Kusalananda's fifo version is closer, but the error propagation parts of the model are genuinely important and not replicable. (all of which I say as someone who is very on the "shell pipelines are just function composition" train)

    – Michael Homer
    Apr 21 at 21:41





    6




    6





    @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

    – Uncle Billy
    Apr 21 at 22:29






    @AlexVong No, that's completely off track. That isn't able to explain even something simple like yes | sed 10q

    – Uncle Billy
    Apr 21 at 22:29





    1




    1





    @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

    – Alex Vong
    Apr 21 at 23:53






    @UncleBilly I agree with your example. This shows that parallel execution is really required also noted by Michael. Otherwise, we'll get non-termination.

    – Alex Vong
    Apr 21 at 23:53














    2














    The term usually used in documentation is "pipeline" , which consists of one or more commands, see POSIX definition So technically speaking, that's two commands you have there, two subprocesses for the shell (either fork()+exec()'ed external commands or subshells )



    As for producer-consumer part, the pipeline can be described by that pattern, since:



    • Producer and Consumer share fixed-size buffer, and at least on Linux and MacOS X, there's fixed size for pipeline buffer

    • Producer and Consumer are loosely-coupled, commands in pipeline don't know of each other's existence ( unless they are actively checking /proc/<pid>/fd directory ).

    • Producers write to stdout and consumers read stdin as if they were a single command being executed, aka they can exist without each other.

    The difference I see here is that unlike Producer-Consumer in other languges, shell commands use buffering and they write stdout once buffer is filled, but there's no mention that Producer-Consumer has to follow that rule - only wait when queue is filled or discard data (which is something else that pipeline doesn't do).






    share|improve this answer



























      2














      The term usually used in documentation is "pipeline" , which consists of one or more commands, see POSIX definition So technically speaking, that's two commands you have there, two subprocesses for the shell (either fork()+exec()'ed external commands or subshells )



      As for producer-consumer part, the pipeline can be described by that pattern, since:



      • Producer and Consumer share fixed-size buffer, and at least on Linux and MacOS X, there's fixed size for pipeline buffer

      • Producer and Consumer are loosely-coupled, commands in pipeline don't know of each other's existence ( unless they are actively checking /proc/<pid>/fd directory ).

      • Producers write to stdout and consumers read stdin as if they were a single command being executed, aka they can exist without each other.

      The difference I see here is that unlike Producer-Consumer in other languges, shell commands use buffering and they write stdout once buffer is filled, but there's no mention that Producer-Consumer has to follow that rule - only wait when queue is filled or discard data (which is something else that pipeline doesn't do).






      share|improve this answer

























        2












        2








        2







        The term usually used in documentation is "pipeline" , which consists of one or more commands, see POSIX definition So technically speaking, that's two commands you have there, two subprocesses for the shell (either fork()+exec()'ed external commands or subshells )



        As for producer-consumer part, the pipeline can be described by that pattern, since:



        • Producer and Consumer share fixed-size buffer, and at least on Linux and MacOS X, there's fixed size for pipeline buffer

        • Producer and Consumer are loosely-coupled, commands in pipeline don't know of each other's existence ( unless they are actively checking /proc/<pid>/fd directory ).

        • Producers write to stdout and consumers read stdin as if they were a single command being executed, aka they can exist without each other.

        The difference I see here is that unlike Producer-Consumer in other languges, shell commands use buffering and they write stdout once buffer is filled, but there's no mention that Producer-Consumer has to follow that rule - only wait when queue is filled or discard data (which is something else that pipeline doesn't do).






        share|improve this answer













        The term usually used in documentation is "pipeline" , which consists of one or more commands, see POSIX definition So technically speaking, that's two commands you have there, two subprocesses for the shell (either fork()+exec()'ed external commands or subshells )



        As for producer-consumer part, the pipeline can be described by that pattern, since:



        • Producer and Consumer share fixed-size buffer, and at least on Linux and MacOS X, there's fixed size for pipeline buffer

        • Producer and Consumer are loosely-coupled, commands in pipeline don't know of each other's existence ( unless they are actively checking /proc/<pid>/fd directory ).

        • Producers write to stdout and consumers read stdin as if they were a single command being executed, aka they can exist without each other.

        The difference I see here is that unlike Producer-Consumer in other languges, shell commands use buffering and they write stdout once buffer is filled, but there's no mention that Producer-Consumer has to follow that rule - only wait when queue is filled or discard data (which is something else that pipeline doesn't do).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 21 at 22:38









        Sergiy KolodyazhnyySergiy Kolodyazhnyy

        10.8k42765




        10.8k42765



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513657%2funderstanding-piped-commands-in-unix-linux%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

            Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

            Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020