[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SIGINT handling during async functions
From: |
Greg Wooledge |
Subject: |
Re: SIGINT handling during async functions |
Date: |
Sat, 21 Jan 2023 08:37:27 -0500 |
On Sat, Jan 21, 2023 at 01:55:27PM +0100, Tycho Kirchner wrote:
> cmd1 &
> cmd2 &
> wait
>
> If the user having launched this script from the interactive terminal aborts
> it by hitting Ctrl+C, by default, the shell sends SIGINT to the process group
> (pgid) of the script. However, while cmd1 and cmd2 get their signal, they
> usually (if they don't override it) ignore it due to above POSIX requirement.
> In my experience, what the user usually wants in such a case is to abort
> cmd1, cmd2 as well as the script having launched them.
A given user might *want* that, but that's not what is going to happen,
nor what is supposed to happen.
If a user wants that behavior, they will need to set up a trap of their
own, store the PIDs of the background processes, and kill them in the
trap.
There is nothing that should be changed in bash with regard to this.
Bash is *already* doing a better job than POSIX requires, with its
EXIT traps that actually do what one expects.