0

A child process created using fork() call inherits file descriptor table of its parent process. In my child process, I would like know about the file descriptors that it inherited from its parent process (and their respective file pointers or the file names that it is pointing at). I know that that entries can be stored in variables that the child process inherits. But, I would like to know about a programming way to retrieve this information.

Tariq Kamal
  • 468
  • 1
  • 8
  • 17
  • 1
    The programming way to retrieve it is to do exactly what you said you already know you can do: store the name and their associated file pointers in a relational construct that can be referred to by the child process after the fork. Anything outside of that is [highly platform-dependent](https://stackoverflow.com/questions/2046515/from-file-object-to-file-name) at best, and not possible more than likely. – WhozCraig Oct 21 '18 at 18:49

2 Answers2

3

Since you tagged this as Linux, you can look in /proc/self/fd/* and /proc/self/fdinfo/*. To get the filename, for example, you can use readlink.

nemequ
  • 16,623
  • 1
  • 43
  • 62
0

You can iterate over all file descriptors starting from 0 and pass them to fstat.

Volker Stolz
  • 7,274
  • 1
  • 32
  • 50