xref: /openbsd-src/usr.bin/fstat/fstat.1 (revision b23d9e582c599c58a54ffa1a1a912c48fb403aad)
1*b23d9e58Sjmc.\"	$OpenBSD: fstat.1,v 1.59 2019/03/31 06:40:26 jmc Exp $
2453cecf0Saaron.\"
3df930be7Sderaadt.\" Copyright (c) 1987, 1991, 1993
4df930be7Sderaadt.\"	The Regents of the University of California.  All rights reserved.
5df930be7Sderaadt.\"
6df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
7df930be7Sderaadt.\" modification, are permitted provided that the following conditions
8df930be7Sderaadt.\" are met:
9df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
10df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
11df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
12df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
13df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
14f75387cbSmillert.\" 3. Neither the name of the University nor the names of its contributors
15df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
16df930be7Sderaadt.\"    without specific prior written permission.
17df930be7Sderaadt.\"
18df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28df930be7Sderaadt.\" SUCH DAMAGE.
29df930be7Sderaadt.\"
30df930be7Sderaadt.\"     from: @(#)fstat.1	8.3 (Berkeley) 2/25/94
31df930be7Sderaadt.\"
321f420de6Sprocter.Dd $Mdocdate: March 31 2019 $
33df930be7Sderaadt.Dt FSTAT 1
342e0eb34fSaaron.Os
35df930be7Sderaadt.Sh NAME
36df930be7Sderaadt.Nm fstat
37b5aa51e6Spjanzen.Nd display status of open files
38df930be7Sderaadt.Sh SYNOPSIS
39df930be7Sderaadt.Nm fstat
40148a7734Smickey.Op Fl fnosv
41df930be7Sderaadt.Op Fl M Ar core
42df930be7Sderaadt.Op Fl N Ar system
43df930be7Sderaadt.Op Fl p Ar pid
44df930be7Sderaadt.Op Fl u Ar user
45666d0576Smillert.Op Ar
46df930be7Sderaadt.Sh DESCRIPTION
473746a816Saaron.Nm
48df930be7Sderaadtidentifies open files.
49df930be7SderaadtA file is considered open by a process if it was explicitly opened,
5064f4df25Smillertis the working directory, root directory, active executable text, or kernel
51df930be7Sderaadttrace file for that process.
52df930be7SderaadtIf no options are specified,
533746a816Saaron.Nm
54df930be7Sderaadtreports on all open files in the system.
55df930be7Sderaadt.Pp
564c2c4eb0SaaronThe options are as follows:
57df930be7Sderaadt.Bl -tag -width Ds
58df930be7Sderaadt.It Fl f
59df930be7SderaadtRestrict examination to files open in the same file systems as
60df930be7Sderaadtthe named file arguments, or to the file system containing the
61df930be7Sderaadtcurrent directory if there are no additional filename arguments.
62df930be7SderaadtFor example, to find all files open in the file system where the
63df930be7Sderaadtdirectory
64df930be7Sderaadt.Pa /usr/src
65df930be7Sderaadtresides, type
66aa85e880Sderaadt.Pp
67e633abafSjmc.Dl # fstat -f /usr/src
68e6a73ab2Sderaadt.It Fl M Ar core
69df930be7SderaadtExtract values associated with the name list from the specified core
70db0d9e21Smiodinstead of the running kernel.
71e6a73ab2Sderaadt.It Fl N Ar system
72db0d9e21SmiodExtract the name list from the specified system instead of the running kernel.
73df930be7Sderaadt.It Fl n
74453cecf0SaaronNumerical format.
75453cecf0SaaronPrint the device number (maj,min) of the file system
76bf9a4e5fSaaronthe file resides in rather than the mount point name.
77bf9a4e5fSaaronFor special files, print the
78df930be7Sderaadtdevice number that the special device refers to rather than the filename
79df930be7Sderaadtin
80453cecf0Saaron.Pa /dev .
81453cecf0SaaronAlso, print the mode of the file in octal instead of symbolic form.
82967a6c35Shugh.It Fl o
83967a6c35ShughOutput file offset.
84967a6c35ShughFollow the size field with the descriptor's offset.
85967a6c35ShughUseful for checking progress as a process works through a large file.
86b749a86cSderaadtThis information is only visible to the user or superuser.
873746a816Saaron.It Fl p Ar pid
88df930be7SderaadtReport all files open by the specified process.
89447c7b0dSmartijnThis option may be specified multiple times.
90148a7734Smickey.It Fl s
91148a7734SmickeyReport per file io statistics in two additional columns
92148a7734Smickey.Sq XFERS
93148a7734Smickeyand
94148a7734Smickey.Sq KBYTES .
95b749a86cSderaadtThis information is only visible to the user or superuser.
963746a816Saaron.It Fl u Ar user
97df930be7SderaadtReport all files open by the specified user.
98447c7b0dSmartijnThis option may be specified multiple times.
99df930be7Sderaadt.It Fl v
100453cecf0SaaronVerbose mode.
101453cecf0SaaronPrint error messages upon failures to locate particular
102453cecf0Saaronsystem data structures rather than silently ignoring them.
103453cecf0SaaronMost of these data structures are dynamically created or deleted and it is
104df930be7Sderaadtpossible for them to disappear while
1053746a816Saaron.Nm
106453cecf0Saaronis running.
107453cecf0SaaronThis is normal and unavoidable since the rest of the system is running while
1083746a816Saaron.Nm
109df930be7Sderaadtitself is running.
110679f6f8fSsobrado.It Ar
111df930be7SderaadtRestrict reports to the specified files.
112df930be7Sderaadt.El
113df930be7Sderaadt.Pp
114df930be7SderaadtThe following fields are printed:
115df930be7Sderaadt.Bl -tag -width MOUNT
116df930be7Sderaadt.It Li USER
117aea1524aSaaronThe username of the owner of the process (effective UID).
118df930be7Sderaadt.It Li CMD
119df930be7SderaadtThe command name of the process.
120df930be7Sderaadt.It Li PID
121aea1524aSaaronThe process ID.
122df930be7Sderaadt.It Li FD
123df930be7SderaadtThe file number in the per-process open file table or one of the following
124df930be7Sderaadtspecial names:
1251f420de6Sprocter.Pp
126*b23d9e58Sjmc.Bl -tag -width "text" -offset indent -compact
1271f420de6Sprocter.It text
1281f420de6Sprocterexecutable text inode
1291f420de6Sprocter.It wd
1301f420de6Sproctercurrent working directory
1311f420de6Sprocter.It root
1321f420de6Sprocterroot inode
1331f420de6Sprocter.It tr
1341f420de6Sprocterkernel trace file
1351f420de6Sprocter.El
136df930be7Sderaadt.Pp
137453cecf0SaaronIf the file number is followed by an asterisk
138453cecf0Saaron.Pq Ql * ,
13988c1c014Spedrothe file is not an inode, but rather a socket, or there is an error.
140df930be7SderaadtIn this case the remainder of the line doesn't
141519cd48eSschwarzecorrespond to the remaining headers \(em the format of the line
142df930be7Sderaadtis described later under
143c7bc5700Sjmc.Sx SOCKETS .
144df930be7Sderaadt.It Li MOUNT
145df930be7SderaadtIf the
146df930be7Sderaadt.Fl n
147df930be7Sderaadtflag wasn't specified, this header is present and is the
148df930be7Sderaadtpathname that the file system the file resides in is mounted on.
149df930be7Sderaadt.It Li DEV
150df930be7SderaadtIf the
151df930be7Sderaadt.Fl n
152df930be7Sderaadtflag is specified, this header is present and is the
153df930be7Sderaadtmajor/minor number of the device that this file resides in.
154df930be7Sderaadt.It Li INUM
155df930be7SderaadtThe inode number of the file.
156368a76ceSguentherIt will be followed by an asterisk
157368a76ceSguenther.Pq Ql *
158368a76ceSguentherif the inode is unlinked from disk.
159df930be7Sderaadt.It Li MODE
160bf9a4e5fSaaronThe mode of the file.
161bf9a4e5fSaaronIf the
162df930be7Sderaadt.Fl n
163df930be7Sderaadtflag isn't specified, the mode is printed
164df930be7Sderaadtusing a symbolic format (see
165df930be7Sderaadt.Xr strmode 3 ) ;
166df930be7Sderaadtotherwise, the mode is printed
167df930be7Sderaadtas an octal number.
168ae6fc983Ssobrado.It Li R/W
169c7db616bSderaadtThis column describes the properties of the file descriptor:
1701f420de6Sprocter.Pp
1711f420de6Sprocter.Bl -tag -width indent -compact
1721f420de6Sprocter.It r
1731f420de6SprocterOpen for reading
1741f420de6Sprocter.It w
1751f420de6SprocterOpen for writing
1761f420de6Sprocter.It e
1771f420de6Sprocterclose-on-exec flag is set
1781f420de6Sprocter.It p
1791f420de6SprocterOpened after
1801f420de6Sprocter.Xr pledge 2
1811f420de6Sprocter.El
182c7db616bSderaadt.Pp
183ae6fc983SsobradoThis field is useful when trying to find the processes that are
184ae6fc983Ssobradopreventing a file system from being downgraded to read-only.
1858580efa1Sjmc.It Li SZ | DV
186aea1524aSaaronIf the file is not a character or block special file, prints the size of
187453cecf0Saaronthe file in bytes.
188453cecf0SaaronOtherwise, if the
189df930be7Sderaadt.Fl n
190df930be7Sderaadtflag is not specified, prints
191df930be7Sderaadtthe name of the special file as located in
192df930be7Sderaadt.Pa /dev .
193453cecf0SaaronIf that cannot be located, or the
194df930be7Sderaadt.Fl n
195df930be7Sderaadtflag is specified, prints the major/minor device
196df930be7Sderaadtnumber that the special device refers to.
197df930be7Sderaadt.It Li NAME
198df930be7SderaadtIf filename arguments are specified and the
199df930be7Sderaadt.Fl f
200df930be7Sderaadtflag is not, then
201df930be7Sderaadtthis field is present and is the name associated with the given file.
202df930be7SderaadtNormally the name cannot be determined since there is no mapping
203df930be7Sderaadtfrom an open file back to the directory entry that was used to open
204453cecf0Saaronthat file.
205453cecf0SaaronAlso, since different directory entries may reference
206df930be7Sderaadtthe same file (via
2079131798cSjmc.Xr ln 1 ) ,
208df930be7Sderaadtthe name printed may not be the actual
209df930be7Sderaadtname that the process originally used to open that file.
210148a7734Smickey.It Li XFERS
2119da62e40SjmcDisplays number of total data transfers performed on the file.
212148a7734Smickey.It Li KBYTES
213148a7734SmickeyDisplays total number of Kbytes written and read to the file.
214df930be7Sderaadt.El
215df930be7Sderaadt.Sh SOCKETS
216f7de5c7bSalexThe formatting of open sockets depends on the protocol domain.
2172345df39SjmcIn all cases the first field is the domain name
2182345df39Sjmcand the second field is the socket type (stream, dgram, etc).
219df930be7SderaadtThe remaining fields are protocol dependent.
220aea1524aSaaronFor TCP, it is the address of the tcpcb, and for UDP, the inpcb (socket pcb).
221d9f1e411SsobradoFor
222f829369eSsobrado.Ux Ns -domain
223f829369eSsobradosockets, it's the address of the socket pcb and the address
224df930be7Sderaadtof the connected pcb (if connected).
225df930be7SderaadtOtherwise the protocol number and address of the socket itself are printed.
226df930be7SderaadtThe attempt is to make enough information available to
227df930be7Sderaadtpermit further analysis without duplicating
228df930be7Sderaadt.Xr netstat 1 .
229df930be7Sderaadt.Pp
230df930be7SderaadtFor example, the addresses mentioned above are the addresses which the
231453cecf0Saaron.Ic netstat -A
232d9f1e411Ssobradocommand would print for TCP, UDP, and
233f829369eSsobrado.Ux Ns -domain.
234dac83430SsthenThese addresses are only visible to the superuser, otherwise 0x0 is printed.
235dac83430SsthenSockets that have been disassociated from a protocol control block
236dac83430Ssthenwill always print 0x0.
237d9f1e411SsobradoA unidirectional
238f829369eSsobrado.Ux Ns -domain
239f829369eSsobradosocket indicates the direction of flow with
240453cecf0Saaronan arrow
241453cecf0Saaron.Pf ( Dq <-
242453cecf0Saaronor
243453cecf0Saaron.Dq -> ) ,
244453cecf0Saaronand a full duplex socket shows a double arrow
245a81d0475Sjmc.Pq Dq <-> .
246f3f48118Sderaadt.Pp
2473746a816SaaronFor
2483746a816Saaron.Dv AF_INET
249a60854cdSguentherand
250a60854cdSguenther.Dv AF_INET6
2513746a816Saaronsockets,
2523746a816Saaron.Nm
253f3f48118Sderaadtalso attempts to print the internet address and port for the
254f3f48118Sderaadtlocal end of a connection.
255f3f48118SderaadtIf the socket is connected, it also prints the remote internet address
256f3f48118Sderaadtand port.
257453cecf0SaaronA
258453cecf0Saaron.Ql *
259453cecf0Saaronis used to indicate an
260453cecf0Saaron.Dv INADDR_ANY
261453cecf0Saaronbinding.
262453cecf0SaaronIn this case, the
263453cecf0Saaronuse of the arrow
264453cecf0Saaron.Pf ( Dq <--
265453cecf0Saaronor
266453cecf0Saaron.Dq --> )
267453cecf0Saaronindicates the direction the socket connection was created.
268a60854cdSguenther.Pp
269e6edc506SjmcIf the socket has been spliced to or from another socket (see
270a60854cdSguenther.Xr setsockopt 2
271a60854cdSguentherand
272188794a2Sjmc.Dv SO_SPLICE )
273188794a2Sjmcthen
274a60854cdSguenther.Nm
275a60854cdSguentherprints a thick arrow
276a60854cdSguenther.Pf ( Dq <==> ,
277a60854cdSguenther.Dq <== ,
278a60854cdSguentheror
279a60854cdSguenther.Dq ==> ) ,
280a60854cdSguentherfollowed by the address and endpoint information of the other socket
281a60854cdSguentherin the splice,
282a60854cdSguentherif available.
283bee62cd9Sart.Sh PIPES
284bee62cd9SartEvery pipe is printed as an address which is the same for both sides of
285453cecf0Saaronthe pipe and a state that is built of the letters
286453cecf0Saaron.Dq RWE .
287a81d0475SjmcW \- The pipe blocks waiting for the reader to read data.
288a81d0475SjmcR \- The pipe blocks waiting for the writer to write data.
289a81d0475SjmcE \- The pipe is in EOF state.
29040039424Sderaadt.Sh KQUEUE
291b96916adSderaadtEach
292b96916adSderaadt.Xr kqueue 2
293b96916adSderaadtis printed with some information as to queue length.
2941a96595fSavsmSince these things are normally serviced quickly, it is likely that
29540039424Sderaadtnothing of real importance can be discerned.
296df930be7Sderaadt.Sh SEE ALSO
297df930be7Sderaadt.Xr netstat 1 ,
298df930be7Sderaadt.Xr nfsstat 1 ,
299df930be7Sderaadt.Xr ps 1 ,
300df930be7Sderaadt.Xr systat 1 ,
301df9e602bSjmc.Xr top 1 ,
302df930be7Sderaadt.Xr iostat 8 ,
303df930be7Sderaadt.Xr pstat 8 ,
3040e63bf27Sjmc.Xr tcpdrop 8 ,
305df930be7Sderaadt.Xr vmstat 8
306df930be7Sderaadt.Sh HISTORY
307df930be7SderaadtThe
308df930be7Sderaadt.Nm
309df930be7Sderaadtcommand appeared in
310df930be7Sderaadt.Bx 4.3 tahoe .
311dd1a9943Sotto.Sh CAVEATS
312dd1a9943SottoSockets in use by the kernel, such as those opened by
313dd1a9943Sotto.Xr nfsd 8 ,
314dd1a9943Sottowill not be seen by
315dd1a9943Sotto.Nm ,
316dd1a9943Sottoeven though they appear in
317dd1a9943Sotto.Xr netstat 1 .
3183746a816Saaron.Sh BUGS
3193746a816SaaronSince
3203746a816Saaron.Nm
3213746a816Saarontakes a snapshot of the system, it is only correct for a very short period
3223746a816Saaronof time.
3233746a816Saaron.Pp
3243746a816SaaronMoreover, because DNS resolution and YP lookups cause many file
3253746a816Saarondescriptor changes,
3263746a816Saaron.Nm
3273746a816Saarondoes not attempt to translate the internet address and port numbers into
3283746a816Saaronsymbolic names.
329