Hi Chet, Conceptually, the availability of a single flag "close-on-exec" (BTW, is there a way to check those flags in bash or using /proc?) should create only 2, not 3 types of file descriptors- that's what I find confusing. Does subprocess creation as in '(llfd)' entail an execve() call? My guess is that no, because the "extended environment" like arrays and function definitions would not survive it, so you'd have to copy them by hand. Either way:
If subprocess creation DOES NOT perform execve(), then I don't understand fd's of type 2, like 60&63: they should continue to exist in a subshell. If subprocess creation DOES perform execve(), then I don't understand fd's of type 3: they should not exist in a subshell. My best guess here is that type 2 is non-standard? Meaning that they are closed by bash during subprocess creation, even though there is no execve()? I only came across those when trying to use coproc... I wonder why this decision was made. Generally speaking, it took me quite some time to figure out how to properly create a "double pipe" without using any intermediate files or fifos. The concept is very easy: in -> tee -> two parallel, independent pipes -> join -> out. A first complication is the limited pipe capacity, and the possibility of one side getting stuck if the other stops pulling in data. I then wrote a cat-like program which doesn't block on stdout, but keeps reading stdin, buffering in as much data as needed. I used it at the very end of either pipe. But then I had to create the actual processes, and then I stumbled upon all these issues with coproc and file descriptors. You leave the wrong one open and the thing gets stuck... I wish there was a howto on this subject. Thanks, M On Tue, Feb 12, 2013 at 2:50 PM, Chet Ramey <chet.ra...@case.edu> wrote: > On 2/12/13 2:07 PM, Matei David wrote: > > > ... there seem to be not 2 but 3(!) types of file descriptors: > > 1. fds which are copied across both subshells and exec; like 4 > > 2. fds which are not copied across subshells; like 60&63 > > 3. fds which are copied across subshells, but not exec; like 10 > > > > I knew about types 1&2, but not about type 3. Apparently with your first > > suggestion, fd 10 is created and survives a subshell creation. Is this > > correct?? > > Yes, file descriptors used to save the state of other file descriptors > are set close-on-exec. `man fcntl' for a description. > > Chet > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, ITS, CWRU c...@case.edu > http://cnswww.cns.cwru.edu/~chet/ >