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

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

                              Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                              Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?