bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SIGINT handling during async functions


From: Tycho Kirchner
Subject: Re: SIGINT handling during async functions
Date: Fri, 13 Jan 2023 08:29:25 +0100



Am 13.01.23 um 03:02 schrieb Robert Elz:
     Date:        Fri, 13 Jan 2023 00:34:02 +0100
     From:        Tycho Kirchner <tychokirchner@mail.de>
     Message-ID:  <7d59c17d-792e-0ac7-fd86-b3b2e7d4b79a@mail.de>

   | we found quite some inconsistency and weirdness
   | in the handling of SIGINT's during async function calls

Not inconsistent or weird, and has nothing to do with
function calls.

   | and were wondering, whether those are expected.

Expected and required.

   | The main INT handler is never executed in foofunc [...]
   | Thus printing the trap apparently changes bash's behavior.

Nonsense (the conclusion)> When an async command (any command, not just functions,
or blocks enclosed in { } ) is run with job control
disabled, SIGINT is ignored for that async command.
(SIGQUIT too).

That has been the way shells work since before either
the Bourne shell (and all later shells based upon it,
like bash) or job control, were invented.

That is all you are seeing here.

kre

Dear Robert Elz,
thanks for the quick response. However, did you actually actually put the short 
snippets into a script, executed it and verified that their behavior is the 
same? In particular, did you check, whether the respective 'sleep' commands 
kept running, after hitting Ctrl+C? On my test system, the 'sleep 3' within 
foofounc **is** killed in the first three code snippets, proving your 
statements wrong. **Only** in case of the 4th snippet, where the trap is 
printed at the beginning of foofunc, the 'sleep 3' command keeps running after 
hitting Ctrl+C.
Let me give another example. Put the following commands into a script test.sh 
and execute it.
______________________________________
bash -c 'echo first; trap -p' & wait
{ bash -c 'echo second; trap -p'; } & wait
{ trap -p >/dev/null; bash -c 'echo third; trap -p'; } & wait
______________________________________

$ ./test.sh
first
trap -- '' SIGINT
trap -- '' SIGQUIT
second
third
trap -- '' SIGINT
______________________________________

So, even in this simple case, differences are observable.
Kind regards
Tycho



reply via email to

[Prev in Thread] Current Thread [Next in Thread]