How to get the filename of a file descriptor?

How to get the filename of a file descriptor?

Post by Ho Man La » Wed, 29 Jan 2003 03:39:58



Does there exist a system call tells the filename/path of a specific
file descriptor.

Ho Man Lam

 
 
 

How to get the filename of a file descriptor?

Post by Ian Pilche » Wed, 29 Jan 2003 03:45:54



> Does there exist a system call tells the filename/path of a specific
> file descriptor.

No.

What would it return for a file that has multiple hard links?
What would it return for a file that has been unlinked (deleted)?

--
========================================================================

========================================================================

 
 
 

How to get the filename of a file descriptor?

Post by James Antil » Wed, 29 Jan 2003 02:20:14



> Does there exist a system call tells the filename/path of a specific
> file descriptor.

 If you don't mind being completely unportable you can look in /proc. Eg.

% touch abcd
% ln abcd xyz
% ( sleep 1m < xyz ) &
[1] 8614
% ls -aslF /proc/8614/fd
total 0
lr-x------    1 james          64 Jan 27 14:47 0 -> /home/james/xyz
lrwx------    1 james          64 Jan 27 14:47 1 -> /dev/pts/15
lrwx------    1 james          64 Jan 27 14:47 2 -> /dev/pts/15