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

How to securely dispose of a smartphone?

80's-90's TV show or movie about life clocks

Do home values typically rise and fall consistently across different price ranges?

Converting Geographic Coordinates into Lambert2008 coordinates

A quine of sorts

"I am [the / an] owner of a bookstore"?

Cooking a nice pan seared steak for picky eaters

How can I open this door latch with the knobs removed?

Security Patch SUPEE-11155 - Possible issues?

How does mmorpg store data?

Cup and Trade: The Perfect Nutmeg Soup

Why wasn't ASCII designed with a contiguous alphanumeric character order?

Undetectable mail tracker

List Manipulation : a,b,c,d,e,f,g,h into a,b,c,d,e,f,g,h

How can combining souls together not increase its volume?

What happens if a caster is surprised while casting a spell with a long casting time?

Calculus, Water Poured into a Cone: Why is Derivative Non-linear?

Closest Proximity of Oceans to Freshwater Springs

Bin Packing with Relational Penalization

Quantum jump/leap, exist or not, and instantaneous or not (for electrons)?

Does friction always oppose motion?

Could you fall off a planet if it was being accelerated by engines?

Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?

Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?



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;








3















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







New contributor



zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    3















    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







    New contributor



    zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      3












      3








      3








      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







      New contributor



      zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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







      New contributor



      zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 8 hours ago









      zambiazzzzambiazzz

      161 bronze badge




      161 bronze badge




      New contributor



      zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      zambiazzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          2 Answers
          2






          active

          oldest

          votes


















          2














          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






























            1














            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
              );



              );






              zambiazzz is a new contributor. Be nice, and check out our Code of Conduct.









              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









              2














              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














                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












                  2








                  2







                  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 8 hours ago









                  RalfFriedlRalfFriedl

                  5,8703 gold badges12 silver badges26 bronze badges




                  5,8703 gold badges12 silver badges26 bronze badges























                      1














                      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



























                        1














                        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

























                          1












                          1








                          1







                          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 8 hours ago









                          KusalanandaKusalananda

                          153k18 gold badges301 silver badges482 bronze badges




                          153k18 gold badges301 silver badges482 bronze badges




















                              zambiazzz is a new contributor. Be nice, and check out our Code of Conduct.









                              draft saved

                              draft discarded


















                              zambiazzz is a new contributor. Be nice, and check out our Code of Conduct.












                              zambiazzz is a new contributor. Be nice, and check out our Code of Conduct.











                              zambiazzz is a new contributor. Be nice, and check out our Code of Conduct.














                              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

                              Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                              Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                              Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її