1.\" Copyright (c) 1987, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)fstat.1 8.3 (Berkeley) 2/25/94 33.\" $FreeBSD$ 34.\" 35.Dd March 27, 2002 36.Dt FSTAT 1 37.Os 38.Sh NAME 39.Nm fstat 40.Nd identify active files 41.Sh SYNOPSIS 42.Nm 43.Op Fl fmnv 44.Op Fl M Ar core 45.Op Fl N Ar system 46.Op Fl p Ar pid 47.Op Fl u Ar user 48.Op Ar 49.Sh DESCRIPTION 50The 51.Nm 52utility identifies open files. 53A file is considered open by a process if it was explicitly opened, 54is the working directory, root directory, active executable text, or kernel 55trace file for that process. 56If no options are specified, 57.Nm 58reports on all open files in the system. 59.Pp 60The following options are available: 61.Bl -tag -width indent 62.It Fl f 63Restrict examination to files open in the same file systems as 64the named file arguments, or to the file system containing the 65current directory if there are no additional filename arguments. 66For example, to find all files open in the file system where the 67directory 68.Pa /usr/src 69resides, type 70.Dq Li fstat -f /usr/src . 71.It Fl M 72Extract values associated with the name list from the specified core 73instead of the default 74.Pa /dev/kmem . 75.It Fl N 76Extract the name list from the specified system instead of the default, 77which is the kernel image the system has booted from. 78.It Fl m 79Include memory-mapped files in the listing; normally these are excluded 80due to the extra processing required. 81.It Fl n 82Numerical format. 83Print the device number (maj,min) of the file system 84the file resides in rather than the mount point name; for special 85files, print the 86device number that the special device refers to rather than the filename 87in 88.Pa /dev ; 89and print the mode of the file in octal instead of symbolic form. 90.It Fl p 91Report all files open by the specified process. 92.It Fl u 93Report all files open by the specified user. 94.It Fl v 95Verbose mode. 96Print error messages upon failures to locate particular 97system data structures rather than silently ignoring them. 98Most of 99these data structures are dynamically created or deleted and it is 100possible for them to disappear while 101.Nm 102is running. 103This 104is normal and unavoidable since the rest of the system is running while 105.Nm 106itself is running. 107.It Ar 108Restrict reports to the specified files. 109.El 110.Pp 111The following fields are printed: 112.Bl -tag -width MOUNT 113.It Li USER 114The username of the owner of the process (effective uid). 115.It Li CMD 116The command name of the process. 117.It Li PID 118The process id. 119.It Li FD 120The file number in the per-process open file table or one of the following 121special names: 122.Pp 123.Bd -literal -offset indent -compact 124text - executable text inode 125wd - current working directory 126root - root inode 127tr - kernel trace file 128mmap - memory-mapped file 129.Ed 130.Pp 131If the file number is followed by an asterisk (``*''), the file is 132not an inode, but rather a socket, 133.Tn FIFO , 134or there is an error. 135In this case the remainder of the line doesn't 136correspond to the remaining headers -- the format of the line 137is described later under 138.Sx Sockets . 139.It Li MOUNT 140If the 141.Fl n 142flag wasn't specified, this header is present and is the 143pathname that the file system the file resides in is mounted on. 144.It Li DEV 145If the 146.Fl n 147flag is specified, this header is present and is the 148major/minor number of the device that this file resides in. 149.It Li INUM 150The inode number of the file. 151.It Li MODE 152The mode of the file. 153If the 154.Fl n 155flag isn't specified, the mode is printed 156using a symbolic format (see 157.Xr strmode 3 ) ; 158otherwise, the mode is printed 159as an octal number. 160.It Li SZ\&|DV 161If the file is not a character or block special, prints the size of 162the file in bytes. 163Otherwise, if the 164.Fl n 165flag is not specified, prints 166the name of the special file as located in 167.Pa /dev . 168If that cannot be 169located, or the 170.Fl n 171flag is specified, prints the major/minor device 172number that the special device refers to. 173.It Li R/W 174This column describes the access mode that the file allows. 175The letter ``r'' indicates open for reading; 176the letter ``w'' indicates open for writing. 177This field is useful when trying to find the processes that are 178preventing a file system from being down graded to read-only. 179.It Li NAME 180If filename arguments are specified and the 181.Fl f 182flag is not, then 183this field is present and is the name associated with the given file. 184Normally the name cannot be determined since there is no mapping 185from an open file back to the directory entry that was used to open 186that file. 187Also, since different directory entries may reference 188the same file (via 189.Xr ln 1 ) , 190the name printed may not be the actual 191name that the process originally used to open that file. 192.El 193.Sh SOCKETS 194The formating of open sockets depends on the protocol domain. 195In all cases the first field is the domain name, the second field 196is the socket type (stream, dgram, etc), and the third is the socket 197flags field (in hex). 198The remaining fields are protocol dependent. 199For tcp, it is the address of the tcpcb, and for udp, the inpcb (socket pcb). 200For unix domain sockets, its the address of the socket pcb and the address 201of the connected pcb (if connected). 202Otherwise the protocol number and address of the socket itself are printed. 203The attempt is to make enough information available to 204permit further analysis without duplicating 205.Xr netstat 1 . 206.Pp 207For example, the addresses mentioned above are the addresses which the 208.Dq Li netstat -A 209command would print for tcp, udp, and unixdomain. 210Note that since pipes are implemented using sockets, a pipe appears as a 211connected unix domain stream socket. 212A unidirectional unix domain socket indicates the direction of flow with 213an arrow (``<-'' or ``->''), and a full duplex socket shows a double arrow 214(``<->''). 215.Sh BUGS 216Since 217.Nm 218takes a snapshot of the system, it is only correct for a very short period 219of time. 220.Sh SEE ALSO 221.Xr netstat 1 , 222.Xr nfsstat 1 , 223.Xr ps 1 , 224.Xr sockstat 1 , 225.Xr systat 1 , 226.Xr tcp 4 , 227.Xr unix 4 , 228.Xr iostat 8 , 229.Xr pstat 8 , 230.Xr vmstat 8 231.Sh HISTORY 232The 233.Nm 234command appeared in 235.Bx 4.3 tahoe . 236