xref: /netbsd-src/usr.bin/fstat/fstat.1 (revision 2555b24764fa81e0512ce8e00df8a4c048511059)
1.\"	$NetBSD: fstat.1,v 1.36 2019/09/06 19:05:04 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 September 6, 2019
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 AfnOv
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 XXXXXXXXXX
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 Ar core
76Extract values associated with the name list from the specified
77.Ar core
78instead of the default
79.Pa /dev/kmem .
80.It Fl N Ar system
81Extract the name list from the specified
82.Ar system
83instead of the default
84.Pa /netbsd .
85.It Fl n
86Numerical format.
87Print the device number (maj,min) of the file system
88the file resides in rather than the mount point name; for special
89files, print the
90device number that the special device refers to rather than the filename
91in
92.Pa /dev ;
93and print the mode of the file in octal instead of symbolic form.
94.It Fl O
95Report file offsets instead of sizes.
96.It Fl p Ar process
97Report all files open by the specified
98.Ar process .
99.It Fl u Ar user
100Report all files open by the specified
101.Ar user .
102.It Fl v
103Verbose mode.
104Print error messages upon failures to locate particular
105system data structures rather than silently ignoring them.
106Most of
107these data structures are dynamically created or deleted and it is
108possible for them to disappear while
109.Nm
110is running.
111This is normal and unavoidable since the rest of the system is running while
112.Nm
113itself is running.
114.It Ar
115Restrict reports to the specified files.
116.El
117.Pp
118The following fields are printed:
119.Bl -tag -width MOUNT
120.It Li USER
121The username of the owner of the process (effective UID).
122.It Li CMD
123The command name of the process.
124.It Li PID
125The process ID.
126.It Li FD
127The file number in the per-process open file table or one of the following
128special names:
129.Pp
130.Bl -tag -width MOUNT -offset indent -compact
131.It Li text
132pure text inode
133.It Li wd
134current working directory
135.It Li root
136root inode
137.It Li tr
138kernel trace file
139.El
140.Pp
141If the file number is followed by an asterisk
142.Pq Dq * ,
143the file is not an inode, but rather a socket,
144.Tn FIFO ,
145or there is an error.
146In this case the remainder of the line doesn't
147correspond to the remaining headers \(em the format of the line
148is described later under
149.Sx SOCKETS .
150.It Li MOUNT
151If the
152.Fl n
153flag wasn't specified, this header is present and is the
154pathname that the file system the file resides in is mounted on.
155.It Li DEV
156If the
157.Fl n
158flag is specified, this header is present and is the
159major/minor number of the device that this file resides in.
160.It Li INUM
161The inode number of the file.
162.It Li MODE
163The mode of the file.
164If the
165.Fl n
166flag isn't specified, the mode is printed
167using a symbolic format (see
168.Xr strmode 3 ) ;
169otherwise, the mode is printed
170as an octal number.
171.It Li SZ\&|DV or OFFS
172If the file is not a character or block special file, prints the size of
173the file in bytes (or the offset if the
174.Fl O
175is specified).
176Otherwise, if the
177.Fl n
178flag is not specified, prints
179the name of the special file as located in
180.Pa /dev .
181If that cannot be
182located, or the
183.Fl n
184flag is specified, prints the major/minor device
185number that the special device refers to.
186.It Li R/W
187This column describes the access mode that the file allows.
188The letter
189.Dq r
190indicates open for reading;
191the letter
192.Dq w
193indicates open for writing.
194This field is useful when trying to find the processes that are
195preventing a file system from being downgraded to read-only.
196.It Li NAME
197If filename arguments are specified and the
198.Fl f
199flag is not, then
200this field is present and is the name associated with the given file.
201Normally the name cannot be determined since there is no mapping
202from an open file back to the directory entry that was used to open
203that file.
204Also, since different directory entries may reference
205the same file (via
206.Xr ln 1 ) ,
207the name printed may not be the actual
208name that the process originally used to open that file.
209.El
210.Sh SOCKETS
211The formatting of open sockets depends on the protocol domain.
212In all cases the first field is the domain name and
213the second field is the socket type (stream, dgram, etc.).
214The remaining fields are protocol dependent.
215For TCP, it is the address of the tcpcb, and for UDP, the inpcb (socket pcb).
216For
217.Ux
218domain sockets, its the address of the socket pcb and the name of the
219file if available.
220Otherwise the address of the connected pcb is printed (if connected).
221For other domains, the protocol number and address of the socket itself
222are printed.
223The attempt is to make enough information available to
224permit further analysis without duplicating
225.Xr netstat 1 .
226.Pp
227For example, the addresses mentioned above are the addresses which the
228.Dq Li netstat -A
229command would print for TCP, UDP, and
230.Ux
231domain.
232For kernels compiled with
233.Dv PIPE_SOCKETPAIR
234pipes appear as connected
235.Ux
236domain stream sockets.
237A unidirectional
238.Ux
239domain socket indicates the direction of flow with an arrow
240.Po
241.Dq <-
242or
243.Dq ->
244.Pc ,
245and a full duplex socket shows a double arrow
246.Pq Dq <-> .
247.Pp
248For internet sockets
249.Nm
250also attempts to print the internet address and port for the
251local end of a connection.
252If the socket is connected, it also prints the remote internet address
253and port.
254An asterisk
255.Pq Dq *
256is used to indicate an INADDR_ANY binding.
257.Sh SEE ALSO
258.Xr netstat 1 ,
259.Xr nfsstat 1 ,
260.Xr ps 1 ,
261.Xr sockstat 1 ,
262.Xr systat 1 ,
263.Xr vmstat 1 ,
264.Xr fstat 2 ,
265.Xr iostat 8 ,
266.Xr pstat 8
267.Sh HISTORY
268The
269.Nm
270command appeared in
271.Bx 4.3 tahoe .
272.Sh BUGS
273Since
274.Nm
275takes a snapshot of the system, it is only correct for a very short period
276of time.
277.Pp
278Moreover, because DNS resolution and YP lookups cause many file
279descriptor changes,
280.Nm
281does not attempt to translate the internet address and port numbers into
282symbolic names.
283.Pp
284Note that the
285.Fl f
286option will not list
287.Ux
288domain sockets open in the file system, because the pathnames in the sockets
289may not be absolute and are not deterministic.
290To find all the
291.Ux
292domain sockets, use
293.Nm
294to list all the sockets, and look for the ones that maybe belong in the
295file system.
296