On 8/5/24 2:21 PM, Zachary Santer wrote:
On Mon, Aug 5, 2024 at 9:54 AM Chet Ramey <chet.ra...@case.edu> wrote:On 7/31/24 11:48 AM, Zachary Santer wrote:$ wait -n > >( cat ) would hang, in the event that there are no other un-waited-for child processes, right?Yes, it will wait for the next job or procsub to terminate.Basically the same situation as Oğuz's bug here:
You mean the one I referenced below, right? https://lists.gnu.org/archive/html/bug-bash/2022-10/msg00107.html Sort of, but they're not the same. The issue with Oguz's bug is that $! had changed before `wait', and was no longer the same as the last process substitution -- the `wait' command should not have waited for it. The other issue was a bookkeeping problem -- even though the process substitution was performed by the same shell that executed the subshell command (because that's how bash optimizes forks), that command shouldn't inherit the process substitutions, since they're logically performed in a different execution context. But in the end, if you're waiting for a process that isn't going to terminate, you're going to be waiting for a long time.
So $! is only set to the pid for a procsub that's being redirected to/from after the command (or compound command) whose output/input isbeing redirected to/from it has completed?
Wow, that's a really complex sentence. And the answer is not really, and it's hard to tell. Since bash performs word expansions before redirections when executing simple commands, all the words in a simple command have been expanded before the process substitution changes $!. So it's not after it's completed, but it's after word expansions have been performed, so it's hard to tell. But if you ran something like this: echo $! <(echo $BASHPID > /dev/tty ) $! the second $! would be expanded to the pid of the procsub because the word expansion changed it. So in your example, the redirection sets $! (or its internal equivalent) to the pid of the procsub, and wait -n waits for it. These operations are performed by the same shell process.
If that's the case, maybe the ideal solution for both 'wait' and 'wait -n' would be to wait for all background jobs and all procsubs that have ever been assigned to $! at that point.
That's all procsubs. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature