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;
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
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
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
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
asked Jun 27 at 20:38
zambiazzzzambiazzz
261 bronze badge
261 bronze badge
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
);
);
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 Jun 27 at 20:55
RalfFriedlRalfFriedl
5,9103 gold badges12 silver badges26 bronze badges
5,9103 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 Jun 27 at 20:53
Kusalananda♦Kusalananda
154k18 gold badges304 silver badges488 bronze badges
154k18 gold badges304 silver badges488 bronze badges
add a comment |
add a comment |
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