[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Examples of concurrent coproc usage?
From: |
felix |
Subject: |
Re: Examples of concurrent coproc usage? |
Date: |
Wed, 17 Apr 2024 11:22:55 +0200 |
Some other way of thinking:
> On 3/14/24 5:58 AM, Carl Edquist wrote:
> > ...
> > But if you try...
> >
> > $ coproc WC { wc; }
> > $ coproc CAT { cat; }
> > $ exec {WC[1]}>&-
> > $ read -u ${WC[0]} X
> >
> > # HANGS
To prevent `exec {WC[1]}>&-` to close both FD, just because subpid is
ended, I open a *backup FD*:
coTest() {
local X WC CAT bakWcOut wcPid
coproc WC { exec wc; }
wcPid=$!
coproc CAT { exec cat; }
echo foo exec bar >&${WC[1]} # Not really usefull for demo
exec {bakWcOut}>&${WC[0]}
exec {WC[1]}>&-
wait $wcPid
read -u ${bakWcOut} X
echo $X
exec {bkWc}>&-
exec {CAT[1]}>&-
wait
ls -l /dev/fd/
}
This function's output look good (on my Debian's bash 5.2.15(1)-release):
$ coTest
[1] 1606
bash: warning: execute_coproc: coproc [1606:WC] still exists
[2] 1607
[1]- Done coproc WC { exec wc; }
1 3 13
[2]+ Done coproc CAT { exec cat; }
total 0
lrwx------ 1 user user 64 Apr 17 11:12 0 -> /dev/pts/3
lrwx------ 1 user user 64 Apr 17 11:12 1 -> /dev/pts/3
lrwx------ 1 user user 64 Apr 17 11:12 2 -> /dev/pts/3
lr-x------ 1 user user 64 Apr 17 11:12 3 -> /proc/1608/fd
--
Félix Hauri - <felix@f-hauri.ch> - http://www.f-hauri.ch
- Re: Examples of concurrent coproc usage?, Chet Ramey, 2024/04/01
- Re: Examples of concurrent coproc usage?, Chet Ramey, 2024/04/03
- Re: Examples of concurrent coproc usage?, Zachary Santer, 2024/04/03
- Message not available
- Message not available
- Message not available
- Message not available
- Message not available
- Re: Examples of concurrent coproc usage?, Zachary Santer, 2024/04/15
- Re: Examples of concurrent coproc usage?, Carl Edquist, 2024/04/16
- Re: Examples of concurrent coproc usage?, Andreas Schwab, 2024/04/16
- Re: Examples of concurrent coproc usage?, Zachary Santer, 2024/04/16