bug-bash
[Top][All Lists]
Advanced

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

Re: eval doesn't close file descriptor?


From: Chet Ramey
Subject: Re: eval doesn't close file descriptor?
Date: Tue, 12 Feb 2013 16:51:43 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 2/12/13 2:07 PM, Matei David wrote:

OK. Let me try this again.  One key to the explanations is that child
processes inherit all of the parent's open file descriptors.

> ... there seem to be not 2 but 3(!) types of file descriptors:
> 1. fds which are copied across both subshells and exec; like 4

File descriptors that are explicitly created by user redirections are
inherited and not set close-on-exec.

> 2. fds which are not copied across subshells; like 60&63

You created a coproc; bash opened pipes to the coproc and is careful to
close those when child processes are created. Having, say, the read end
of a pipe open in multiple processes really messes with SIGPIPE generation.
Multiple fds open for write means that read will never see EOF, even if the
process you intend to write to it exits.

This is true for pipes in general, so bash is very careful to keep track of
file descriptors open on pipes and close them in child processes.

> 3. fds which are copied across subshells, but not exec; like 10

File descriptors which are used internally to save state of file
descriptors used in redirections are set close-on-exec.

> 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.  A subshell gets copies of its parent's file descriptors.

Chet

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



reply via email to

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