[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: coproc does not work in subshell
From: |
Chet Ramey |
Subject: |
Re: coproc does not work in subshell |
Date: |
Fri, 2 Oct 2020 10:12:50 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 |
On 10/2/20 7:59 AM, Hyunho Cho wrote:
> bash$ ( echo "1 + 5" >& ${COPROC[1]}; read -r <& ${COPROC[0]}; echo
> $REPLY ) # ERROR : subshell does not work
> bash: ${COPROC[1]}: Bad file descriptor
> bash: ${COPROC[0]}: Bad file descriptor
> 3
Yes, this is correct. Subshells close coproc file descriptors they inherit.
This is to prevent deadlock and processes not terminating because there are
still open file descriptors to child processes. If you want to manage the
file descriptors yourself, you can dup the coproc file descriptors and make
sure they're closed appropriately for your needs.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/