bug-bash
[Top][All Lists]
Advanced

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

Re: 5.0 regression: Script stuck when waiting in trap


From: Chet Ramey
Subject: Re: 5.0 regression: Script stuck when waiting in trap
Date: Tue, 4 Jun 2019 19:19:02 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

On 6/4/19 4:34 PM, mwnx wrote:

> Thanks for the explanation. In view of the change you describe,
> there is another behaviour that I think might qualify as a bug. I'll
> give you my actual use case first.
> 
> I simply want to make sure all processes running inside a given
> subshell are killed on exit. To that means, I set up the following
> trap in the shell (and potentially, its subshells and so on):
> 
>     trap 'kill $(jobs -p) &>/dev/null || true; wait' EXIT
> 
> This was working fine in bash 4.x, despite `jobs -p` not returning
> the process ID of process substitutions. But now that `wait` (with
> no arguments) waits for process substitutions in addition to
> "ordinary" foreground and background processes, the situation is
> asymmetric, leading to my subshells freezing when killed while a
> process substitution is running.

Not quite. `wait' without arguments waits for the last process
substitution, and the pid of that process is available in $! for the
cases you care about. If you are sure that your script hasn't started
any asynchronous processes since the last process substitution, you
can use $! directly. Otherwise, you can capture it into a variable
and use it in the `kill' command.

You should also ensure that you're using bash-5.0 with patch 4 applied,
since that is relevant to this issue.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

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