bug-bash
[Top][All Lists]
Advanced

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

Re: Process substitution file consumed?


From: Chet Ramey
Subject: Re: Process substitution file consumed?
Date: Sat, 06 Aug 2011 10:53:15 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11

On 8/2/11 10:08 AM, Maarten Billemont wrote:
> In the following snippet, I expect the two ls' to give the same output.  
> However, it appears the process substitution's temporary file sometimes 
> vanishes for the second.  Can someone explain why and whether this is the 
> desired behavior or not?
> 
> A Linux (2.6.27.6) VM in a QEMU says this:
> 
> # moo() { ls -l "$1"; ls -l "$1"; }; moo >(true)
> l-wx------ 1 root root 64 Aug  2 14:00 /dev/fd/63 -> pipe:[245]
> ls: cannot access /dev/fd/63: No such file or directory
> 
> A Linux (2.6.32-5-amd64) machine says this:
> 
> # moo() { ls -l "$1"; ls -l "$1"; }; moo >(true)
> l-wx------ 1 devel devel 1 Aug  2 16:03 /dev/fd/63 -> pipe:[527968]
> l-wx------ 1 devel devel 1 Aug  2 16:03 /dev/fd/63 -> pipe:[527968]
> 
> My Mac says this:
> 
> # moo() { ls -l "$1"; ls -l "$1"; }; moo >(true)
> prw-rw----  0 lhunath  staff  0  2 Aug 15:55 /dev/fd/63|
> prw-rw----  0 lhunath  staff  0  2 Aug 15:55 /dev/fd/63|
> 
> And the latter two break again when I toss a (true) inbetween the two ls':
> 
> # moo() { ls -al "$1"; (true); ls -al "$1"; }; moo >(true)
> l-wx------ 1 devel devel 1 Aug  2 16:06 /dev/fd/63 -> pipe:[528022]
> ls: cannot access /dev/fd/63: No such file or directory
> 
> # moo() { ls -al "$1"; (true); ls -al "$1"; }; moo >(true)
> prw-rw----  0 lhunath  staff  0  2 Aug 16:07 /dev/fd/63|
> ls: /dev/fd/63: Bad file descriptor
> 
> Surely neither case where the FD can no longer be accessed or its file has 
> disappeared can be correct behavior?

Thanks for the report.  It's the subshell that makes the difference here:
bash-4.2, and probably earlier versions, is too aggressive about closing
file descriptors pointing to process substitutions in the parent process,
when they should persist until any executing shell function completes.

The first example (the Linux VM) was fixed between bash-4.0 and bash-4.1.

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



reply via email to

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