On Fri, 7 Jun 2002, at 2:53pm, Jerry Feldman wrote:
> The dup2(2) system calls simply duplicates to file descriptor.
The important part about dup2(2) is that it lets you specify the file
descriptor you want opened, since STDOUT is just a symbolic name for "file
descriptor number 1".
> Also, I could be wrong, but when a child process starts it inherits all
> the parent's open file descriptors.
You are correct, AFAIK.
> I don't believe that the parent shell closes 0, 1, or 2 at all.
The *parent* shell does not. What actually happens, I imagine, is that
the shell (the parent) opens the redirection targets as it would any other
file. Then it does the fork(). The child process then closes the old
std{in,out,err} descriptors, reopens them based on the redirection file
descriptors inherited from the parent, and then does the exec().
The point I was trying to make was that the parent shell is not involved
in the I/O of the redirected process at all. The child simply has the
standard file descriptors set to something other than the parent's terminal.
> The freopen(3) C function does close the open file descriptor associated
> with the FILE structure, and then opens a new file to be associated with
> it.
The code may very well use freopen(3) instead of dup2(3) directly. At
some point, though, freopen(3) has to be implemented in terms of dup2(2) (or
some other, similar system call I am not aware of).
--
Ben Scott <[EMAIL PROTECTED]>
| The opinions expressed in this message are those of the author and do not |
| necessarily represent the views or policy of any other person, entity or |
| organization. All information is provided without warranty of any kind. |
*****************************************************************
To unsubscribe from this list, send mail to [EMAIL PROTECTED]
with the text 'unsubscribe gnhlug' in the message body.
*****************************************************************