The fd Directory

The directory /proc/$pid/fd has an entry for each open file descriptor as a symbolic link to the actual file’s inode. An inode contains information about a file. Each inode has the device where the inode resides, locking information, mode and filetype of the file, links to the file, user and group ids of the owner, bytes in the file, and addresses of the file’s blocks on the disk.

Opening the file descriptor entry (for example, /proc/self/fd/1) opens the file itself; if the file is a terminal or other special device, it may interfere with the process itself by stealing data. You can also use the fstat() or lstat() system calls to get information about the file. The permissions shown for the file have access for the owner only and the owner read and owner write bits indicate the mode in which the file is open. There is a utility program that runs on many UNIX systems, with and without /proc filesystems, called lsof. On a Red Hat system, it is installed in /usr/sbin/lsof.

This can be handy when you want to get information on what a process is doing, want to know why you can’t unmound a particular filesystem because it is busy, or want to investigate suspicious activity. The fuser command is similar but searches for specific files. If you have an old distribution or did not do a full install, you may be missing these utilities.

Posted on: 18/12/2009








0 Comments
If you want to leave a comment please Login or Register
How to backup your data using rsync......
Understanding autoconf......
The Basics of fdisk......
Accessing Memory Using DMA......
The fd Directory......