On Tue, Jul 9, 2024 at 6:12 AM Zachary Santer <zsan...@gmail.com> wrote: > > command-1 | tee >( command-2 ) >( command-3 ) >( command-4 ) > wait > > The workaround for this not working would of course be named pipes, > which is somewhat less trivial.
> Bash is already tracking the pids for all child processes not waited > on, internally. So I imagine it wouldn't be too much work to make that > information available to the script it's running. Obviously, this is > moving beyond "make the existing features make more sense," but an > array of pids of all child processes not waited on would at least > allow the user to derive pids of what just got forked from a > comparison of that array before and after a command including multiple > procsubs. An array variable like what Alex is suggesting, something > listing all pids resulting from the last pipeline to fork any child > process in the current shell environment, would be a solution to the > matter at hand here. > > Maybe a single middle-ground array variable, listing the pids of all > child processes forked (and not waited on) since the last time the > array variable was referenced, would be more easily implemented. You > would just have to save the contents of the array variable in a > variable of your own each time you reference it, if you want to keep > track of that stuff. Not unreasonable, considering that you already > have to do that with $!, at least before each time you fork another > child process. On the other hand, do funsubs give us the answer here? shopt -s lastpipe declare -a pid=() command-1 | tee >( command-2 ) ${ pid+=( "${!}" ); } >( command-3 ) ${ pid+=( "${!}" ); } >( command-4 ) ${ pid+=( "${!}" ); } wait -- "${pid[@]}" That looks obnoxious, and I should probably get Cygwin going and build bash-5.3-alpha for myself instead of just asking if this would work and is sane. That could take me 'til the weekend, though. On Tue, Jul 9, 2024 at 6:12 AM Zachary Santer <zsan...@gmail.com> wrote: > > On Fri, Jul 5, 2024 at 3:16 PM Chet Ramey <chet.ra...@case.edu> wrote: > > > > On 7/3/24 8:40 PM, Zachary Santer wrote: > > > > > > Hypothetically, it could work like this: > > > { > > > commands > > > } {fd[0]}< <( command-1 ) {fd[1]}< <( command-2 ) {fd[2]}< <( command-3 ) > > > But then again, *I can't get the pids for the processes if I do it this > > > way*. declare -a pid=() { commands } {fd[0]}< <( command-1 ) ${ pid+=( "${!}" ); } {fd[1]}< <( command-2 ) ${ pid+=( "${!}" ); } {fd[2]}< <( command-3 ) ${ pid+=( "${!}" ); } Do things start breaking?