Behavior of a pipe after a fork()

Posted by Steve Melvin on Stack Overflow See other posts from Stack Overflow or by Steve Melvin
Published on 2010-03-11T21:16:37Z Indexed on 2010/03/11 21:19 UTC
Read the original article Hit count: 447

Filed under:
|
|
|

When reading about pipes in Advanced Programming in the UNIX Environment, I noticed that after a fork that the parent can close() the read end of a pipe and it doesn't close the read end for the child. When a process forks, does its file descriptors get retained? What I mean by this is that before the fork the pipe read file descriptor had a retain count of 1, and after the fork 2. When the parent closed its read side the fd went to 1 and is kept open for the child. Is this essentially what is happening? Does this behavior also occur for regular file descriptors?

© Stack Overflow or respective owner

Related posts about c

    Related posts about unix