How to handle async subshell exitexit shell script from a subshellRunning a “scheduled”/delayed script as sudo on server, via ssh - and right before ssh exitWhere is `exit` defined?How to run subshell commands over SSH?Wait for foreground process to emit string, then send to backgroundSSH connections running in the background don't exit if multiple connections have been started by the same shellHow to Group Commands After '&&' or '||' Branch and Not Invoke Subshell Variable Restriction?Bash find if all env variables are declared, by variable namegrabbing exit code of background process/subshellBackground process of subshell strange behaviour

Sense of humor in your sci-fi stories

Can you create a free-floating MASYU puzzle?

Interpretation of non-significant results as "trends"

What was the nature of the known bugs in the Space Shuttle software?

How to deal with account scam and fraud?

What's the difference between a type and a kind?

Attach a visible light telescope to the outside of the ISS

Users forgotting to regenerate PDF before sending it

Gory anime with pink haired girl escaping an asylum

How can I review my manager, who is fine?

Passwordless authentication - how and when to invalidate a login code

NOLOCK or Read Uncommitted locking / latching behaviours

What is the highest level of accuracy in motion control a Victorian society could achieve?

How to understand flavors and when to use combination of them?

Diagram with cylinder shapes and rectangles

What is the shape of the upper boundary of water hitting a screen?

Function that detects repetitions

Shipped package arrived - didn't order, possible scam?

Why did Robert F. Kennedy loathe Lyndon B. Johnson?

As a supervisor, what feedback would you expect from a PhD who quits?

What purpose does mercury dichloride have in fireworks?

How to reclaim personal item I've lent to the office without burning bridges?

Taking my Ph.D. advisor out for dinner after graduation

What is this burst transmission sequence across the entire band?



How to handle async subshell exit


exit shell script from a subshellRunning a “scheduled”/delayed script as sudo on server, via ssh - and right before ssh exitWhere is `exit` defined?How to run subshell commands over SSH?Wait for foreground process to emit string, then send to backgroundSSH connections running in the background don't exit if multiple connections have been started by the same shellHow to Group Commands After '&&' or '||' Branch and Not Invoke Subshell Variable Restriction?Bash find if all env variables are declared, by variable namegrabbing exit code of background process/subshellBackground process of subshell strange behaviour






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








5















Say I have this:



set -e;

(
docker stop notifier-server
docker rm -f notifier-server
exit 1 # explicitly exit with non-zero
) &

wait;

echo 'we are here now'


will we always get to the echo line, even if the subshell exits with non-zero? I assume so, since it's a backend process/subshell?



What's the right way to look at this?










share|improve this question




























    5















    Say I have this:



    set -e;

    (
    docker stop notifier-server
    docker rm -f notifier-server
    exit 1 # explicitly exit with non-zero
    ) &

    wait;

    echo 'we are here now'


    will we always get to the echo line, even if the subshell exits with non-zero? I assume so, since it's a backend process/subshell?



    What's the right way to look at this?










    share|improve this question
























      5












      5








      5








      Say I have this:



      set -e;

      (
      docker stop notifier-server
      docker rm -f notifier-server
      exit 1 # explicitly exit with non-zero
      ) &

      wait;

      echo 'we are here now'


      will we always get to the echo line, even if the subshell exits with non-zero? I assume so, since it's a backend process/subshell?



      What's the right way to look at this?










      share|improve this question














      Say I have this:



      set -e;

      (
      docker stop notifier-server
      docker rm -f notifier-server
      exit 1 # explicitly exit with non-zero
      ) &

      wait;

      echo 'we are here now'


      will we always get to the echo line, even if the subshell exits with non-zero? I assume so, since it's a backend process/subshell?



      What's the right way to look at this?







      bash shell background-process subshell






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 27 at 20:38









      zambiazzzzambiazzz

      261 bronze badge




      261 bronze badge




















          2 Answers
          2






          active

          oldest

          votes


















          3














          It is not related to the process being a background process, it is related to the exit status of the wait command.



          From help wait:




          If ID is not given, waits for all currently active child processes, and the return status is zero.




          $ bash -exc '(sleep 1; exit 1) & wait ; echo done'
          + wait
          + sleep 1
          + exit 1
          + echo done
          done



          If the -n option is supplied, waits for the next job to terminate and returns its exit status.




          $ bash -exc '(sleep 1; exit 1) & wait -n; echo $?:done'
          + wait -n
          + sleep 1
          + exit 1





          share|improve this answer






























            2














            Your code would not terminate the current shell session since no non-zero exit status is returned to it. The result in the calling shell of starting a background job is always zero.



            Would you have used wait "$!" or wait -n ("wait for next job to finish"), then the shell session would have terminated since wait would have returned the exit status of the job that it waited for, which is non-zero.



            See help wait in bash.






            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%2f527352%2fhow-to-handle-async-subshell-exit%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









              3














              It is not related to the process being a background process, it is related to the exit status of the wait command.



              From help wait:




              If ID is not given, waits for all currently active child processes, and the return status is zero.




              $ bash -exc '(sleep 1; exit 1) & wait ; echo done'
              + wait
              + sleep 1
              + exit 1
              + echo done
              done



              If the -n option is supplied, waits for the next job to terminate and returns its exit status.




              $ bash -exc '(sleep 1; exit 1) & wait -n; echo $?:done'
              + wait -n
              + sleep 1
              + exit 1





              share|improve this answer



























                3














                It is not related to the process being a background process, it is related to the exit status of the wait command.



                From help wait:




                If ID is not given, waits for all currently active child processes, and the return status is zero.




                $ bash -exc '(sleep 1; exit 1) & wait ; echo done'
                + wait
                + sleep 1
                + exit 1
                + echo done
                done



                If the -n option is supplied, waits for the next job to terminate and returns its exit status.




                $ bash -exc '(sleep 1; exit 1) & wait -n; echo $?:done'
                + wait -n
                + sleep 1
                + exit 1





                share|improve this answer

























                  3












                  3








                  3







                  It is not related to the process being a background process, it is related to the exit status of the wait command.



                  From help wait:




                  If ID is not given, waits for all currently active child processes, and the return status is zero.




                  $ bash -exc '(sleep 1; exit 1) & wait ; echo done'
                  + wait
                  + sleep 1
                  + exit 1
                  + echo done
                  done



                  If the -n option is supplied, waits for the next job to terminate and returns its exit status.




                  $ bash -exc '(sleep 1; exit 1) & wait -n; echo $?:done'
                  + wait -n
                  + sleep 1
                  + exit 1





                  share|improve this answer













                  It is not related to the process being a background process, it is related to the exit status of the wait command.



                  From help wait:




                  If ID is not given, waits for all currently active child processes, and the return status is zero.




                  $ bash -exc '(sleep 1; exit 1) & wait ; echo done'
                  + wait
                  + sleep 1
                  + exit 1
                  + echo done
                  done



                  If the -n option is supplied, waits for the next job to terminate and returns its exit status.




                  $ bash -exc '(sleep 1; exit 1) & wait -n; echo $?:done'
                  + wait -n
                  + sleep 1
                  + exit 1






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 27 at 20:55









                  RalfFriedlRalfFriedl

                  5,9103 gold badges12 silver badges26 bronze badges




                  5,9103 gold badges12 silver badges26 bronze badges























                      2














                      Your code would not terminate the current shell session since no non-zero exit status is returned to it. The result in the calling shell of starting a background job is always zero.



                      Would you have used wait "$!" or wait -n ("wait for next job to finish"), then the shell session would have terminated since wait would have returned the exit status of the job that it waited for, which is non-zero.



                      See help wait in bash.






                      share|improve this answer



























                        2














                        Your code would not terminate the current shell session since no non-zero exit status is returned to it. The result in the calling shell of starting a background job is always zero.



                        Would you have used wait "$!" or wait -n ("wait for next job to finish"), then the shell session would have terminated since wait would have returned the exit status of the job that it waited for, which is non-zero.



                        See help wait in bash.






                        share|improve this answer

























                          2












                          2








                          2







                          Your code would not terminate the current shell session since no non-zero exit status is returned to it. The result in the calling shell of starting a background job is always zero.



                          Would you have used wait "$!" or wait -n ("wait for next job to finish"), then the shell session would have terminated since wait would have returned the exit status of the job that it waited for, which is non-zero.



                          See help wait in bash.






                          share|improve this answer













                          Your code would not terminate the current shell session since no non-zero exit status is returned to it. The result in the calling shell of starting a background job is always zero.



                          Would you have used wait "$!" or wait -n ("wait for next job to finish"), then the shell session would have terminated since wait would have returned the exit status of the job that it waited for, which is non-zero.



                          See help wait in bash.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 27 at 20:53









                          KusalanandaKusalananda

                          154k18 gold badges304 silver badges488 bronze badges




                          154k18 gold badges304 silver badges488 bronze badges



























                              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%2f527352%2fhow-to-handle-async-subshell-exit%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

                              Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                              Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                              Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form