display status of open files
fstat identifies open files. A file is
considered open by a process if it was explicitly opened, is the working
directory, root directory, active executable text, or kernel trace file for
that process. If no options are specified,
reports on all open files in the system.
The options are as follows:
- Restrict examination to files open in the same file systems as the named
file arguments, or to the file system containing the current directory if
there are no additional filename arguments. For example, to find all files
open in the file system where the directory
/usr/src resides, type
# fstat -f /usr/src
- Extract values associated with the name list from the specified core instead of the running kernel.
- Extract the name list from the specified system instead of the running kernel.
- Numerical format. Print the device number (maj,min) of the file system the file resides in rather than the mount point name. For special files, print the device number that the special device refers to rather than the filename in /dev. Also, print the mode of the file in octal instead of symbolic form.
- Output file offset. Follow the size field with the descriptor's offset. Useful for checking progress as a process works through a large file. This information is only visible to the user or superuser.
- Report all files open by the specified process.
- Report per file io statistics in two additional columns ‘XFERS’ and ‘KBYTES’. This information is only visible to the user or superuser.
- Report all files open by the specified user.
- Verbose mode. Print error messages upon failures to locate particular
system data structures rather than silently ignoring them. Most of these
data structures are dynamically created or deleted and it is possible for
them to disappear while
fstatis running. This is normal and unavoidable since the rest of the system is running while
fstatitself is running.
- file ...
- Restrict reports to the specified files.
The following fields are printed:
- The username of the owner of the process (effective UID).
- The command name of the process.
- The process ID.
- The file number in the per-process open file table or one of the following
text - executable text inode wd - current working directory root - root inode tr - kernel trace file
If the file number is followed by an asterisk (‘
*’), the file is not an inode, but rather a socket, or there is an error. In this case the remainder of the line doesn't correspond to the remaining headers — the format of the line is described later under SOCKETS.
- If the
-nflag wasn't specified, this header is present and is the pathname that the file system the file resides in is mounted on.
- If the
-nflag is specified, this header is present and is the major/minor number of the device that this file resides in.
- The inode number of the file. It will be followed by an asterisk
*’) if the inode is unlinked from disk.
- The mode of the file. If the
-nflag isn't specified, the mode is printed using a symbolic format (see strmode(3)); otherwise, the mode is printed as an octal number.
- This column describes the properties of the file descriptor:
r Open for reading w Open for writing e close-on-exec flag is set
This field is useful when trying to find the processes that are preventing a file system from being downgraded to read-only.
- If the file is not a character or block special file, prints the size of
the file in bytes. Otherwise, if the
-nflag is not specified, prints the name of the special file as located in /dev. If that cannot be located, or the
-nflag is specified, prints the major/minor device number that the special device refers to.
- If filename arguments are specified and the
-fflag is not, then this field is present and is the name associated with the given file. Normally the name cannot be determined since there is no mapping from an open file back to the directory entry that was used to open that file. Also, since different directory entries may reference the same file (via ln(1)), the name printed may not be the actual name that the process originally used to open that file.
- Displays number of total data transfers performed on the file.
- Displays total number of Kbytes written and read to the file.
The formatting of open sockets depends on the protocol domain. In all cases the first field is the domain name and the second field is the socket type (stream, dgram, etc). The remaining fields are protocol dependent. For TCP, it is the address of the tcpcb, and for UDP, the inpcb (socket pcb). For UNIX-domain sockets, it's the address of the socket pcb and the address of the connected pcb (if connected). Otherwise the protocol number and address of the socket itself are printed. The attempt is to make enough information available to permit further analysis without duplicating netstat(1).
For example, the addresses mentioned above are the addresses which
netstat -A command would print for TCP, UDP, and
UNIX-domain. These addresses are only visible to the
superuser, otherwise 0x0 is printed. Sockets that have been disassociated
from a protocol control block will always print 0x0. A unidirectional
UNIX-domain socket indicates the direction of flow
with an arrow (“<-” or “->”), and a full
duplex socket shows a double arrow (“<->”).
attempts to print the internet address and port for the local end of a
connection. If the socket is connected, it also prints the remote internet
address and port. A ‘
*’ is used to
INADDR_ANY binding. In this case, the
use of the arrow (“<--” or “-->”)
indicates the direction the socket connection was created.
If the socket has been spliced to or from another socket (see
fstat prints a thick arrow
(“<==>”, “<==”, or
“==>”), followed by the address and endpoint information of
the other socket in the splice, if available.
Every pipe is printed as an address which is the same for both sides of the pipe and a state that is built of the letters “RWE”. W - The pipe blocks waiting for the reader to read data. R - The pipe blocks waiting for the writer to write data. E - The pipe is in EOF state.
Each kqueue(2) is printed with some information as to queue length. Since these things are normally serviced quickly, it is likely that nothing of real importance can be discerned.
netstat(1), nfsstat(1), ps(1), systat(1), top(1), iostat(8), pstat(8), tcpdrop(8), vmstat(8)
fstat command appeared in
Sockets in use by the kernel, such as those opened by
nfsd(8), will not be seen by
though they appear in
fstat takes a snapshot of the
system, it is only correct for a very short period of time.
Moreover, because DNS resolution and YP lookups cause many file
fstat does not attempt to
translate the internet address and port numbers into symbolic names.