xref: /openbsd/usr.bin/fstat/fstat.1 (revision fc61954a)
1.\"	$OpenBSD: fstat.1,v 1.53 2016/10/02 23:16:08 guenther 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 $Mdocdate: October 2 2016 $
33.Dt FSTAT 1
34.Os
35.Sh NAME
36.Nm fstat
37.Nd display status of open files
38.Sh SYNOPSIS
39.Nm fstat
40.Op Fl fnosv
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 executable 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
56The options are as follows:
57.Bl -tag -width Ds
58.It Fl f
59Restrict examination to files open in the same file systems as
60the named file arguments, or to the file system containing the
61current directory if there are no additional filename arguments.
62For example, to find all files open in the file system where the
63directory
64.Pa /usr/src
65resides, type
66.Pp
67.Dl # fstat -f /usr/src
68.It Fl M Ar core
69Extract values associated with the name list from the specified core
70instead of the running kernel.
71.It Fl N Ar system
72Extract the name list from the specified system instead of the running kernel.
73.It Fl n
74Numerical format.
75Print the device number (maj,min) of the file system
76the file resides in rather than the mount point name.
77For special files, print the
78device number that the special device refers to rather than the filename
79in
80.Pa /dev .
81Also, print the mode of the file in octal instead of symbolic form.
82.It Fl o
83Output file offset.
84Follow the size field with the descriptor's offset.
85Useful for checking progress as a process works through a large file.
86This information is only visible to the user or superuser.
87.It Fl p Ar pid
88Report all files open by the specified process.
89.It Fl s
90Report per file io statistics in two additional columns
91.Sq XFERS
92and
93.Sq KBYTES .
94This information is only visible to the user or superuser.
95.It Fl u Ar user
96Report all files open by the specified user.
97.It Fl v
98Verbose mode.
99Print error messages upon failures to locate particular
100system data structures rather than silently ignoring them.
101Most of these data structures are dynamically created or deleted and it is
102possible for them to disappear while
103.Nm
104is running.
105This is normal and unavoidable since the rest of the system is running while
106.Nm
107itself is running.
108.It Ar
109Restrict reports to the specified files.
110.El
111.Pp
112The following fields are printed:
113.Bl -tag -width MOUNT
114.It Li USER
115The username of the owner of the process (effective UID).
116.It Li CMD
117The command name of the process.
118.It Li PID
119The process ID.
120.It Li FD
121The file number in the per-process open file table or one of the following
122special names:
123.Bd -literal -offset indent
124text	\- executable text inode
125wd	\- current working directory
126root	\- root inode
127tr	\- kernel trace file
128.Ed
129.Pp
130If the file number is followed by an asterisk
131.Pq Ql * ,
132the file is not an inode, but rather a socket, or there is an error.
133In this case the remainder of the line doesn't
134correspond to the remaining headers -- the format of the line
135is described later under
136.Sx SOCKETS .
137.It Li MOUNT
138If the
139.Fl n
140flag wasn't specified, this header is present and is the
141pathname that the file system the file resides in is mounted on.
142.It Li DEV
143If the
144.Fl n
145flag is specified, this header is present and is the
146major/minor number of the device that this file resides in.
147.It Li INUM
148The inode number of the file.
149It will be followed by an asterisk
150.Pq Ql *
151if the inode is unlinked from disk.
152.It Li MODE
153The mode of the file.
154If the
155.Fl n
156flag isn't specified, the mode is printed
157using a symbolic format (see
158.Xr strmode 3 ) ;
159otherwise, the mode is printed
160as an octal number.
161.It Li R/W
162This column describes the access mode that the file allows.
163The letter
164.Sq r
165indicates open for reading;
166the letter
167.Sq w
168indicates open for writing.
169This field is useful when trying to find the processes that are
170preventing a file system from being downgraded to read-only.
171.It Li SZ | DV
172If the file is not a character or block special file, prints the size of
173the file in bytes.
174Otherwise, if the
175.Fl n
176flag is not specified, prints
177the name of the special file as located in
178.Pa /dev .
179If that cannot be located, or the
180.Fl n
181flag is specified, prints the major/minor device
182number that the special device refers to.
183.It Li NAME
184If filename arguments are specified and the
185.Fl f
186flag is not, then
187this field is present and is the name associated with the given file.
188Normally the name cannot be determined since there is no mapping
189from an open file back to the directory entry that was used to open
190that file.
191Also, since different directory entries may reference
192the same file (via
193.Xr ln 1 ) ,
194the name printed may not be the actual
195name that the process originally used to open that file.
196.It Li XFERS
197Displays number of total data transfers performed on the file.
198.It Li KBYTES
199Displays total number of Kbytes written and read to the 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
204and the 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 Ns -domain
209sockets, it's the address of the socket pcb and the address
210of the connected pcb (if connected).
211Otherwise the protocol number and address of the socket itself are printed.
212The attempt is to make enough information available to
213permit further analysis without duplicating
214.Xr netstat 1 .
215.Pp
216For example, the addresses mentioned above are the addresses which the
217.Ic netstat -A
218command would print for TCP, UDP, and
219.Ux Ns -domain.
220A unidirectional
221.Ux Ns -domain
222socket indicates the direction of flow with
223an arrow
224.Pf ( Dq <-
225or
226.Dq -> ) ,
227and a full duplex socket shows a double arrow
228.Pq Dq <-> .
229.Pp
230For
231.Dv AF_INET
232and
233.Dv AF_INET6
234sockets,
235.Nm
236also attempts to print the internet address and port for the
237local end of a connection.
238If the socket is connected, it also prints the remote internet address
239and port.
240A
241.Ql *
242is used to indicate an
243.Dv INADDR_ANY
244binding.
245In this case, the
246use of the arrow
247.Pf ( Dq <--
248or
249.Dq --> )
250indicates the direction the socket connection was created.
251.Pp
252If the socket has been spliced to or from another socket (see
253.Xr setsockopt 2
254and
255.Dv SO_SPLICE )
256then
257.Nm
258prints a thick arrow
259.Pf ( Dq <==> ,
260.Dq <== ,
261or
262.Dq ==> ) ,
263followed by the address and endpoint information of the other socket
264in the splice,
265if available.
266.Sh PIPES
267Every pipe is printed as an address which is the same for both sides of
268the pipe and a state that is built of the letters
269.Dq RWE .
270W \- The pipe blocks waiting for the reader to read data.
271R \- The pipe blocks waiting for the writer to write data.
272E \- The pipe is in EOF state.
273.Sh KQUEUE
274Each
275.Xr kqueue 2
276is printed with some information as to queue length.
277Since these things are normally serviced quickly, it is likely that
278nothing of real importance can be discerned.
279.Sh SEE ALSO
280.Xr netstat 1 ,
281.Xr nfsstat 1 ,
282.Xr ps 1 ,
283.Xr systat 1 ,
284.Xr top 1 ,
285.Xr iostat 8 ,
286.Xr pstat 8 ,
287.Xr tcpdrop 8 ,
288.Xr vmstat 8
289.Sh HISTORY
290The
291.Nm
292command appeared in
293.Bx 4.3 tahoe .
294.Sh CAVEATS
295Sockets in use by the kernel, such as those opened by
296.Xr nfsd 8 ,
297will not be seen by
298.Nm ,
299even though they appear in
300.Xr netstat 1 .
301.Sh BUGS
302Since
303.Nm
304takes a snapshot of the system, it is only correct for a very short period
305of time.
306.Pp
307Moreover, because DNS resolution and YP lookups cause many file
308descriptor changes,
309.Nm
310does not attempt to translate the internet address and port numbers into
311symbolic names.
312