Why does bash exit immediately when waiting for a command to complete and receives SIGHUP for which a trap has been set?

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
From Bash manual
If Bash is waiting for a command to complete and receives a signal for
which a trap has been set, the trap will not be executed until the
command completes.
When Bash is waiting for an asynchronous command via the wait builtin,
the reception of a signal for which a trap has been set will cause the
wait builtin to return immediately with an exit status greater than
128, immediately after which the trap is executed.
I created some experiments for the first sentence.
In a shell running in a tab in lxterminal:
$ trap "echo hello" HUP
$ sleep 100I then close the tab window, so that send SIGHUP to the shell.
The shell exits immediately, instead of waiting for
sleep 100to
complete, and then executing the trap. I was wondering why? Did I
miss something?This one works
$ trap -p
trap -- 'echo hello' SIGHUP
$ echo $$
19708
$ sleep 100Then run from another tab of lxterminal:
$ kill -HUP 19708
$When the sleep command in the first tab completes:
$ sleep 100
hello
Thanks.
Related When typing ctrl-c in a terminal, why isn't the foreground job terminated until it completes?
bash signals trap
add a comment |Â
up vote
2
down vote
favorite
From Bash manual
If Bash is waiting for a command to complete and receives a signal for
which a trap has been set, the trap will not be executed until the
command completes.
When Bash is waiting for an asynchronous command via the wait builtin,
the reception of a signal for which a trap has been set will cause the
wait builtin to return immediately with an exit status greater than
128, immediately after which the trap is executed.
I created some experiments for the first sentence.
In a shell running in a tab in lxterminal:
$ trap "echo hello" HUP
$ sleep 100I then close the tab window, so that send SIGHUP to the shell.
The shell exits immediately, instead of waiting for
sleep 100to
complete, and then executing the trap. I was wondering why? Did I
miss something?This one works
$ trap -p
trap -- 'echo hello' SIGHUP
$ echo $$
19708
$ sleep 100Then run from another tab of lxterminal:
$ kill -HUP 19708
$When the sleep command in the first tab completes:
$ sleep 100
hello
Thanks.
Related When typing ctrl-c in a terminal, why isn't the foreground job terminated until it completes?
bash signals trap
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
From Bash manual
If Bash is waiting for a command to complete and receives a signal for
which a trap has been set, the trap will not be executed until the
command completes.
When Bash is waiting for an asynchronous command via the wait builtin,
the reception of a signal for which a trap has been set will cause the
wait builtin to return immediately with an exit status greater than
128, immediately after which the trap is executed.
I created some experiments for the first sentence.
In a shell running in a tab in lxterminal:
$ trap "echo hello" HUP
$ sleep 100I then close the tab window, so that send SIGHUP to the shell.
The shell exits immediately, instead of waiting for
sleep 100to
complete, and then executing the trap. I was wondering why? Did I
miss something?This one works
$ trap -p
trap -- 'echo hello' SIGHUP
$ echo $$
19708
$ sleep 100Then run from another tab of lxterminal:
$ kill -HUP 19708
$When the sleep command in the first tab completes:
$ sleep 100
hello
Thanks.
Related When typing ctrl-c in a terminal, why isn't the foreground job terminated until it completes?
bash signals trap
From Bash manual
If Bash is waiting for a command to complete and receives a signal for
which a trap has been set, the trap will not be executed until the
command completes.
When Bash is waiting for an asynchronous command via the wait builtin,
the reception of a signal for which a trap has been set will cause the
wait builtin to return immediately with an exit status greater than
128, immediately after which the trap is executed.
I created some experiments for the first sentence.
In a shell running in a tab in lxterminal:
$ trap "echo hello" HUP
$ sleep 100I then close the tab window, so that send SIGHUP to the shell.
The shell exits immediately, instead of waiting for
sleep 100to
complete, and then executing the trap. I was wondering why? Did I
miss something?This one works
$ trap -p
trap -- 'echo hello' SIGHUP
$ echo $$
19708
$ sleep 100Then run from another tab of lxterminal:
$ kill -HUP 19708
$When the sleep command in the first tab completes:
$ sleep 100
hello
Thanks.
Related When typing ctrl-c in a terminal, why isn't the foreground job terminated until it completes?
bash signals trap
edited May 27 at 23:04
asked May 27 at 22:03
Tim
22.6k61222401
22.6k61222401
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446361%2fwhy-does-bash-exit-immediately-when-waiting-for-a-command-to-complete-and-receiv%23new-answer', 'question_page');
);
Post as a guest
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
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
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