If the child process alters its file descriptor table, does it affect the parent's?

Viewed 59

I'm writing a C program that involves forking a child process to call dup2 to intercept stdout to write to a file. I was wondering if the child process alters the file descriptor table for the parent process if I call dup2(fd, 1). Would it alter the FD table for the parent, or because the child has a copy of the table it would be fine?

1 Answers

No, it doesn't, and that's the point. If you seek an fd, it affects the parent though, because it really is two handles to the same open file descriptor.

Related