how can I get filename from file descriptor?

T. William Wells bill at twwells.com
Fri Aug 18 15:31:51 AEST 1989


In article <20613 at adm.BRL.MIL> Pabbisetty.henr at xerox.com (Nagesh Pabbisetty) writes:
: If I have a descriptor to a file, how can I find out the name of the file
: associated with it?

For most practical purposes, you don't.

1) A file descriptor may not have a path associated with it. Consider
   a file that is opened and then unlinked.

2) A file descriptor may have more than one path to it. Consider
   multiply linked files.

Assuming that neither of the above is true, the best you can do is to
get the device and inode number of the file and then search the
device's entire directory tree for the inode.

Ugh.

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill at twwells.com



More information about the Comp.unix.wizards mailing list