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;
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
bash shell background-process subshell
New contributor
New contributor
New contributor
asked 8 hours ago
zambiazzzzambiazzz
161 bronze badge
161 bronze badge
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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
.
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered 8 hours ago
RalfFriedlRalfFriedl
5,8703 gold badges12 silver badges26 bronze badges
5,8703 gold badges12 silver badges26 bronze badges
add a comment |
add a comment |
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered 8 hours ago
Kusalananda♦Kusalananda
153k18 gold badges301 silver badges482 bronze badges
153k18 gold badges301 silver badges482 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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