1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
.\" $OpenBSD: fstat.1,v 1.53 2016/10/02 23:16:08 guenther Exp $
.\"
.\" Copyright (c) 1987, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)fstat.1 8.3 (Berkeley) 2/25/94
.\"
.Dd $Mdocdate: October 2 2016 $
.Dt FSTAT 1
.Os
.Sh NAME
.Nm fstat
.Nd display status of open files
.Sh SYNOPSIS
.Nm fstat
.Op Fl fnosv
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl p Ar pid
.Op Fl u Ar user
.Op Ar
.Sh DESCRIPTION
.Nm
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,
.Nm
reports on all open files in the system.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl f
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
.Pa /usr/src
resides, type
.Pp
.Dl # fstat -f /usr/src
.It Fl M Ar core
Extract values associated with the name list from the specified core
instead of the running kernel.
.It Fl N Ar system
Extract the name list from the specified system instead of the running kernel.
.It Fl n
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
.Pa /dev .
Also, print the mode of the file in octal instead of symbolic form.
.It Fl o
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.
.It Fl p Ar pid
Report all files open by the specified process.
.It Fl s
Report per file io statistics in two additional columns
.Sq XFERS
and
.Sq KBYTES .
This information is only visible to the user or superuser.
.It Fl u Ar user
Report all files open by the specified user.
.It Fl v
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
.Nm
is running.
This is normal and unavoidable since the rest of the system is running while
.Nm
itself is running.
.It Ar
Restrict reports to the specified files.
.El
.Pp
The following fields are printed:
.Bl -tag -width MOUNT
.It Li USER
The username of the owner of the process (effective UID).
.It Li CMD
The command name of the process.
.It Li PID
The process ID.
.It Li FD
The file number in the per-process open file table or one of the following
special names:
.Bd -literal -offset indent
text \- executable text inode
wd \- current working directory
root \- root inode
tr \- kernel trace file
.Ed
.Pp
If the file number is followed by an asterisk
.Pq Ql * ,
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
.Sx SOCKETS .
.It Li MOUNT
If the
.Fl n
flag wasn't specified, this header is present and is the
pathname that the file system the file resides in is mounted on.
.It Li DEV
If the
.Fl n
flag is specified, this header is present and is the
major/minor number of the device that this file resides in.
.It Li INUM
The inode number of the file.
It will be followed by an asterisk
.Pq Ql *
if the inode is unlinked from disk.
.It Li MODE
The mode of the file.
If the
.Fl n
flag isn't specified, the mode is printed
using a symbolic format (see
.Xr strmode 3 ) ;
otherwise, the mode is printed
as an octal number.
.It Li R/W
This column describes the access mode that the file allows.
The letter
.Sq r
indicates open for reading;
the letter
.Sq w
indicates open for writing.
This field is useful when trying to find the processes that are
preventing a file system from being downgraded to read-only.
.It Li SZ | DV
If the file is not a character or block special file, prints the size of
the file in bytes.
Otherwise, if the
.Fl n
flag is not specified, prints
the name of the special file as located in
.Pa /dev .
If that cannot be located, or the
.Fl n
flag is specified, prints the major/minor device
number that the special device refers to.
.It Li NAME
If filename arguments are specified and the
.Fl f
flag 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
.Xr ln 1 ) ,
the name printed may not be the actual
name that the process originally used to open that file.
.It Li XFERS
Displays number of total data transfers performed on the file.
.It Li KBYTES
Displays total number of Kbytes written and read to the file.
.El
.Sh SOCKETS
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
.Ux Ns -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
.Xr netstat 1 .
.Pp
For example, the addresses mentioned above are the addresses which the
.Ic netstat -A
command would print for TCP, UDP, and
.Ux Ns -domain.
A unidirectional
.Ux Ns -domain
socket indicates the direction of flow with
an arrow
.Pf ( Dq <-
or
.Dq -> ) ,
and a full duplex socket shows a double arrow
.Pq Dq <-> .
.Pp
For
.Dv AF_INET
and
.Dv AF_INET6
sockets,
.Nm
also 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
.Ql *
is used to indicate an
.Dv INADDR_ANY
binding.
In this case, the
use of the arrow
.Pf ( Dq <--
or
.Dq --> )
indicates the direction the socket connection was created.
.Pp
If the socket has been spliced to or from another socket (see
.Xr setsockopt 2
and
.Dv SO_SPLICE )
then
.Nm
prints a thick arrow
.Pf ( Dq <==> ,
.Dq <== ,
or
.Dq ==> ) ,
followed by the address and endpoint information of the other socket
in the splice,
if available.
.Sh PIPES
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
.Dq 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.
.Sh KQUEUE
Each
.Xr 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.
.Sh SEE ALSO
.Xr netstat 1 ,
.Xr nfsstat 1 ,
.Xr ps 1 ,
.Xr systat 1 ,
.Xr top 1 ,
.Xr iostat 8 ,
.Xr pstat 8 ,
.Xr tcpdrop 8 ,
.Xr vmstat 8
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 tahoe .
.Sh CAVEATS
Sockets in use by the kernel, such as those opened by
.Xr nfsd 8 ,
will not be seen by
.Nm ,
even though they appear in
.Xr netstat 1 .
.Sh BUGS
Since
.Nm
takes a snapshot of the system, it is only correct for a very short period
of time.
.Pp
Moreover, because DNS resolution and YP lookups cause many file
descriptor changes,
.Nm
does not attempt to translate the internet address and port numbers into
symbolic names.
|