1.\" $NetBSD: fstat.1,v 1.34 2017/07/03 21:34:57 wiz Exp $ 2.\" 3.\" Copyright (c) 1987, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" from: @(#)fstat.1 8.3 (Berkeley) 2/25/94 31.\" 32.Dd December 15, 2013 33.Dt FSTAT 1 34.Os 35.Sh NAME 36.Nm fstat 37.Nd display status of open files 38.Sh SYNOPSIS 39.Nm 40.Op Fl Afnv 41.Op Fl M Ar core 42.Op Fl N Ar system 43.Op Fl p Ar pid 44.Op Fl u Ar user 45.Op Ar 46.Sh DESCRIPTION 47.Nm 48identifies open files. 49A file is considered open by a process if it was explicitly opened, 50is the working directory, root directory, active pure text, or kernel 51trace file for that process. 52If no options are specified, 53.Nm 54reports on all open files in the system. 55.Pp 56Options: 57.Bl -tag -width Ds 58.It Fl A 59Add an output column with the address of the kernel object (vnode or file), 60that can be matched with 61.Xr pstat 8 62output. 63.It Fl f 64Restrict examination to files open in the same file systems as 65the named file arguments, or to the file system containing the 66current directory if there are no additional filename arguments. 67For example, to find all files open in the file system where the 68directory 69.Pa /var/log 70resides, type 71.Dq Li fstat -f /var/log . 72Please see the 73.Sx BUGS 74section for issues with this option. 75.It Fl M 76Extract values associated with the name list from the specified core 77instead of the default 78.Pa /dev/kmem . 79.It Fl N 80Extract the name list from the specified system instead of the default 81.Pa /netbsd . 82.It Fl n 83Numerical format. 84Print the device number (maj,min) of the file system 85the file resides in rather than the mount point name; for special 86files, print the 87device number that the special device refers to rather than the filename 88in 89.Pa /dev ; 90and print the mode of the file in octal instead of symbolic form. 91.It Fl p 92Report all files open by the specified process. 93.It Fl u 94Report all files open by the specified user. 95.It Fl v 96Verbose mode. 97Print error messages upon failures to locate particular 98system data structures rather than silently ignoring them. 99Most of 100these data structures are dynamically created or deleted and it is 101possible for them to disappear while 102.Nm 103is running. 104This is 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.Bl -tag -width MOUNT -offset indent -compact 124.It Li text 125pure text inode 126.It Li wd 127current working directory 128.It Li root 129root inode 130.It Li tr 131kernel trace file 132.El 133.Pp 134If the file number is followed by an asterisk 135.Pq Dq * , 136the file is not an inode, but rather a socket, 137.Tn FIFO , 138or there is an error. 139In this case the remainder of the line doesn't 140correspond to the remaining headers -- the format of the line 141is described later under 142.Sx SOCKETS . 143.It Li MOUNT 144If the 145.Fl n 146flag wasn't specified, this header is present and is the 147pathname that the file system the file resides in is mounted on. 148.It Li DEV 149If the 150.Fl n 151flag is specified, this header is present and is the 152major/minor number of the device that this file resides in. 153.It Li INUM 154The inode number of the file. 155.It Li MODE 156The mode of the file. 157If the 158.Fl n 159flag isn't specified, the mode is printed 160using a symbolic format (see 161.Xr strmode 3 ) ; 162otherwise, the mode is printed 163as an octal number. 164.It Li SZ\&|DV 165If the file is not a character or block special file, prints the size of 166the file in bytes. 167Otherwise, if the 168.Fl n 169flag is not specified, prints 170the name of the special file as located in 171.Pa /dev . 172If that cannot be 173located, or the 174.Fl n 175flag is specified, prints the major/minor device 176number that the special device refers to. 177.It Li R/W 178This column describes the access mode that the file allows. 179The letter 180.Dq r 181indicates open for reading; 182the letter 183.Dq w 184indicates open for writing. 185This field is useful when trying to find the processes that are 186preventing a file system from being downgraded to read-only. 187.It Li NAME 188If filename arguments are specified and the 189.Fl f 190flag is not, then 191this field is present and is the name associated with the given file. 192Normally the name cannot be determined since there is no mapping 193from an open file back to the directory entry that was used to open 194that file. 195Also, since different directory entries may reference 196the same file (via 197.Xr ln 1 ) , 198the name printed may not be the actual 199name that the process originally used to open that file. 200.El 201.Sh SOCKETS 202The formatting of open sockets depends on the protocol domain. 203In all cases the first field is the domain name and 204the second field is the socket type (stream, dgram, etc.). 205The remaining fields are protocol dependent. 206For TCP, it is the address of the tcpcb, and for UDP, the inpcb (socket pcb). 207For 208.Ux 209domain sockets, its the address of the socket pcb and the name of the 210file if available. 211Otherwise the address of the connected pcb is printed (if connected). 212For other domains, the protocol number and address of the socket itself 213are printed. 214The attempt is to make enough information available to 215permit further analysis without duplicating 216.Xr netstat 1 . 217.Pp 218For example, the addresses mentioned above are the addresses which the 219.Dq Li netstat -A 220command would print for TCP, UDP, and 221.Ux 222domain. 223For kernels compiled with 224.Dv PIPE_SOCKETPAIR 225pipes appear as connected 226.Ux 227domain stream sockets. 228A unidirectional 229.Ux 230domain socket indicates the direction of flow with an arrow 231.Po 232.Dq <- 233or 234.Dq -> 235.Pc , 236and a full duplex socket shows a double arrow 237.Pq Dq <-> . 238.Pp 239For internet sockets 240.Nm 241also attempts to print the internet address and port for the 242local end of a connection. 243If the socket is connected, it also prints the remote internet address 244and port. 245An asterisk 246.Pq Dq * 247is used to indicate an INADDR_ANY binding. 248.Sh SEE ALSO 249.Xr netstat 1 , 250.Xr nfsstat 1 , 251.Xr ps 1 , 252.Xr sockstat 1 , 253.Xr systat 1 , 254.Xr vmstat 1 , 255.Xr fstat 2 , 256.Xr iostat 8 , 257.Xr pstat 8 258.Sh HISTORY 259The 260.Nm 261command appeared in 262.Bx 4.3 tahoe . 263.Sh BUGS 264Since 265.Nm 266takes a snapshot of the system, it is only correct for a very short period 267of time. 268.Pp 269Moreover, because DNS resolution and YP lookups cause many file 270descriptor changes, 271.Nm 272does not attempt to translate the internet address and port numbers into 273symbolic names. 274.Pp 275Note that the 276.Fl f 277option will not list 278.Ux 279domain sockets open in the file system, because the pathnames in the sockets 280may not be absolute and are not deterministic. 281To find all the 282.Ux 283domain sockets, use 284.Nm 285to list all the sockets, and look for the ones that maybe belong in the 286file system. 287