Is coproc the same as &?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have read that $coproc < command > is different from $< command > & in that coproc will execute command in a sub-shell process.



But when I tested it, it worked just like $< command > &. The test is as follow:



First: test the behavior of $< command > &.



  1. Run $nano & on tty1

  2. On another tty, output from $ps -t tty1 --forest indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)

Second: test the behavior of $coproc < command >



  1. Run $coproc nano on tty1

  2. On another tty, output from $ps -t tty1 --forest is the same as above (no sub-shell process was created)

So is $coproc < command > simply the same as $< command > &?



The shell used was a bash shell










share|improve this question





















  • Possible duplicate of How do you use the command coproc in various shells?
    – Stéphane Chazelas
    13 mins ago














up vote
2
down vote

favorite












I have read that $coproc < command > is different from $< command > & in that coproc will execute command in a sub-shell process.



But when I tested it, it worked just like $< command > &. The test is as follow:



First: test the behavior of $< command > &.



  1. Run $nano & on tty1

  2. On another tty, output from $ps -t tty1 --forest indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)

Second: test the behavior of $coproc < command >



  1. Run $coproc nano on tty1

  2. On another tty, output from $ps -t tty1 --forest is the same as above (no sub-shell process was created)

So is $coproc < command > simply the same as $< command > &?



The shell used was a bash shell










share|improve this question





















  • Possible duplicate of How do you use the command coproc in various shells?
    – Stéphane Chazelas
    13 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have read that $coproc < command > is different from $< command > & in that coproc will execute command in a sub-shell process.



But when I tested it, it worked just like $< command > &. The test is as follow:



First: test the behavior of $< command > &.



  1. Run $nano & on tty1

  2. On another tty, output from $ps -t tty1 --forest indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)

Second: test the behavior of $coproc < command >



  1. Run $coproc nano on tty1

  2. On another tty, output from $ps -t tty1 --forest is the same as above (no sub-shell process was created)

So is $coproc < command > simply the same as $< command > &?



The shell used was a bash shell










share|improve this question













I have read that $coproc < command > is different from $< command > & in that coproc will execute command in a sub-shell process.



But when I tested it, it worked just like $< command > &. The test is as follow:



First: test the behavior of $< command > &.



  1. Run $nano & on tty1

  2. On another tty, output from $ps -t tty1 --forest indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)

Second: test the behavior of $coproc < command >



  1. Run $coproc nano on tty1

  2. On another tty, output from $ps -t tty1 --forest is the same as above (no sub-shell process was created)

So is $coproc < command > simply the same as $< command > &?



The shell used was a bash shell







bash coprocesses






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Tran Triet

748




748











  • Possible duplicate of How do you use the command coproc in various shells?
    – Stéphane Chazelas
    13 mins ago
















  • Possible duplicate of How do you use the command coproc in various shells?
    – Stéphane Chazelas
    13 mins ago















Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago




Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













coproc utility is not the same as utility & in bash.



With coproc utility you get an array, COPROC, that contains the standard input and output filedescriptors of utility. You may then do things like



#!/bin/bash

coproc bc -l

for (( k = 0; k < 50; ++k )); do
printf "2.3*%d + 1n" "$k" >&$COPROC[1]
read -u "$COPROC[0]" a
printf '%.2fn' "$a"
done

kill "$COPROC_PID"


Here, bc -l is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.



As far as I can tell, bash also only supports one co-process at any one time. The ksh93 shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).






share|improve this answer





























    up vote
    0
    down vote













    The difference is the creation of two I/O channels, as described in man bash:




    A coprocess is executed asynchronously in a subshell, as if the
    command had been terminated with
    the & control operator, with a two-way pipe established between the executing shell and the coprocess.







    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',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      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%2f472561%2fis-coproc-command-the-same-as-command%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      coproc utility is not the same as utility & in bash.



      With coproc utility you get an array, COPROC, that contains the standard input and output filedescriptors of utility. You may then do things like



      #!/bin/bash

      coproc bc -l

      for (( k = 0; k < 50; ++k )); do
      printf "2.3*%d + 1n" "$k" >&$COPROC[1]
      read -u "$COPROC[0]" a
      printf '%.2fn' "$a"
      done

      kill "$COPROC_PID"


      Here, bc -l is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.



      As far as I can tell, bash also only supports one co-process at any one time. The ksh93 shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).






      share|improve this answer


























        up vote
        2
        down vote













        coproc utility is not the same as utility & in bash.



        With coproc utility you get an array, COPROC, that contains the standard input and output filedescriptors of utility. You may then do things like



        #!/bin/bash

        coproc bc -l

        for (( k = 0; k < 50; ++k )); do
        printf "2.3*%d + 1n" "$k" >&$COPROC[1]
        read -u "$COPROC[0]" a
        printf '%.2fn' "$a"
        done

        kill "$COPROC_PID"


        Here, bc -l is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.



        As far as I can tell, bash also only supports one co-process at any one time. The ksh93 shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).






        share|improve this answer
























          up vote
          2
          down vote










          up vote
          2
          down vote









          coproc utility is not the same as utility & in bash.



          With coproc utility you get an array, COPROC, that contains the standard input and output filedescriptors of utility. You may then do things like



          #!/bin/bash

          coproc bc -l

          for (( k = 0; k < 50; ++k )); do
          printf "2.3*%d + 1n" "$k" >&$COPROC[1]
          read -u "$COPROC[0]" a
          printf '%.2fn' "$a"
          done

          kill "$COPROC_PID"


          Here, bc -l is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.



          As far as I can tell, bash also only supports one co-process at any one time. The ksh93 shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).






          share|improve this answer














          coproc utility is not the same as utility & in bash.



          With coproc utility you get an array, COPROC, that contains the standard input and output filedescriptors of utility. You may then do things like



          #!/bin/bash

          coproc bc -l

          for (( k = 0; k < 50; ++k )); do
          printf "2.3*%d + 1n" "$k" >&$COPROC[1]
          read -u "$COPROC[0]" a
          printf '%.2fn' "$a"
          done

          kill "$COPROC_PID"


          Here, bc -l is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.



          As far as I can tell, bash also only supports one co-process at any one time. The ksh93 shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 10 mins ago

























          answered 16 mins ago









          Kusalananda

          107k14209331




          107k14209331






















              up vote
              0
              down vote













              The difference is the creation of two I/O channels, as described in man bash:




              A coprocess is executed asynchronously in a subshell, as if the
              command had been terminated with
              the & control operator, with a two-way pipe established between the executing shell and the coprocess.







              share|improve this answer
























                up vote
                0
                down vote













                The difference is the creation of two I/O channels, as described in man bash:




                A coprocess is executed asynchronously in a subshell, as if the
                command had been terminated with
                the & control operator, with a two-way pipe established between the executing shell and the coprocess.







                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The difference is the creation of two I/O channels, as described in man bash:




                  A coprocess is executed asynchronously in a subshell, as if the
                  command had been terminated with
                  the & control operator, with a two-way pipe established between the executing shell and the coprocess.







                  share|improve this answer












                  The difference is the creation of two I/O channels, as described in man bash:




                  A coprocess is executed asynchronously in a subshell, as if the
                  command had been terminated with
                  the & control operator, with a two-way pipe established between the executing shell and the coprocess.








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  RudiC

                  1,5979




                  1,5979



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472561%2fis-coproc-command-the-same-as-command%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      Confectionery