getting the pathname to an open file

Brian Matthews 6sigma2 at polari.UUCP
Sun Jan 13 06:34:35 AEST 1991


In article <DENAP.91Jan11134939 at alta.sw.stratus.com> denap at alta.sw.stratus.com (Tom DeNapoli) writes:
|Has anyone got anything that will return the absolute pathname of
|an open file to a process?  

In general, this can't always be done.  Consider:

fd = open (file, 0); unlink (file); ... do stuff with fd ...

There is no path corresponding to fd after the unlink.  A similar problem
occurs if fd is a pipe or a stream.

You can do a search of the file system, but that would be abominably slow,
and could fail anyways.

|Process A has file ./dir1/dir2/foo open and he wants the absolute
|path to the file as in /usr/local/stuff/dir1/dir2.  

If process A has dir1/dir2/foo open and hasn't changed directories,
then the path is `pwd`/dir1/dir2/foo (assuming foo hasn't been unlinked
by process A or some other process).  In general, if you need to have
the full path, you should first rethink your design, and if you still
need it, stash it when you open the file, realizing that it may go
away without notice.
-- 
Brian L. Matthews	6sigma2 at polari.UUCP



More information about the Comp.unix.programmer mailing list