PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs323] File Descriptors
Date: Sunday, 15 Nov 2020, 19:40:09


    > Message Posted By: Unknown
    >
    > When you change file descriptor 1 or 0 when reading or writing a file, how
    > do we rever those file descriptors back to stdin or stdout. For example,
    > when redirecting, I think we need to change fd 1 and 0 to the fd of
    > whatever file is opened, but then we would need to change fd 1 and 0 back
    > to its original right? Do we need to store the original fd values somewhere?

Yes, if you redirect stdin and stdout in the parent
shell, you will need to redirect them.  You can use
dup2() or dup() to do so.

But you can also do redirection in the child process,
as was done in Hwk5/pipe.c.

--Stan-
PREV INDEX NEXT