File descriptors before fork ()

I know that if I call the function openbefore fork(), the IO pointer is shared between processes.

If one of these processes closes the file calling the function close(fd), will the other processes still be able to write / read the file or will the file be closed to everyone?

+4
source share
2 answers

Yes. Each process has a copy of the file descriptor (among other things). Thus, one process closing it will not affect the copy fdin another process.

From the fork()manual:

          .            (. open (2))            . ,            , ,           (. F_SETOWN           F_SETSIG fcntl (2)).

close() :

fd ,         (. open (2)), ,         ;         , unlink (2),        .

, close(fd);, , , , .

+7

, , . , , , . , , , , , . , .

+2

All Articles