xref: /freebsd/usr.bin/fstat/fstat.1 (revision 3416500aef140042c64bc149cb1ec6620483bc44)
1.\" Copyright (c) 1987, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)fstat.1	8.3 (Berkeley) 2/25/94
29.\" $FreeBSD$
30.\"
31.Dd September 28, 2011
32.Dt FSTAT 1
33.Os
34.Sh NAME
35.Nm fstat
36.Nd identify active files
37.Sh SYNOPSIS
38.Nm
39.Op Fl fmnv
40.Op Fl M Ar core
41.Op Fl N Ar system
42.Op Fl p Ar pid
43.Op Fl u Ar user
44.Op Ar
45.Sh DESCRIPTION
46The
47.Nm
48utility identifies open files.
49A file is considered open by a process if it was explicitly opened,
50is the working directory, root directory, jail root directory,
51active executable text, or kernel trace file for that process.
52If no options are specified,
53.Nm
54reports on all open files in the system.
55.Pp
56The following options are available:
57.Bl -tag -width indent
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.Dq Li fstat -f /usr/src .
67.It Fl M
68Extract values associated with the name list from the specified core
69instead of the default
70.Pa /dev/kmem .
71.It Fl N
72Extract the name list from the specified system instead of the default,
73which is the kernel image the system has booted from.
74.It Fl m
75Include memory-mapped files in the listing; normally these are excluded
76due to the extra processing required.
77.It Fl n
78Numerical format.
79Print the device number (maj,min) of the file system
80the file resides in rather than the mount point name; for special
81files, print the
82device number that the special device refers to rather than the filename
83in
84.Pa /dev ;
85and print the mode of the file in octal instead of symbolic form.
86.It Fl p
87Report all files open by the specified process.
88.It Fl u
89Report all files open by the specified user.
90.It Fl v
91Verbose mode.
92Print error messages upon failures to locate particular
93system data structures rather than silently ignoring them.
94Most of
95these data structures are dynamically created or deleted and it is
96possible for them to disappear while
97.Nm
98is running.
99This
100is normal and unavoidable since the rest of the system is running while
101.Nm
102itself is running.
103.It Ar
104Restrict reports to the specified files.
105.El
106.Pp
107The following fields are printed:
108.Bl -tag -width MOUNT
109.It Li USER
110The username of the owner of the process (effective uid).
111.It Li CMD
112The command name of the process.
113.It Li PID
114The process id.
115.It Li FD
116The file number in the per-process open file table or one of the following
117special names:
118.Pp
119.Bd -literal -offset indent -compact
120jail	- jail root directory
121mmap	- memory-mapped file
122root	- root inode
123text	- executable text inode
124tr	- kernel trace file
125wd 	- current working directory
126.Ed
127.Pp
128If the file number is followed by an asterisk (``*''), the file is
129not an inode, but rather a socket,
130.Tn FIFO ,
131or there is an error.
132In this case the remainder of the line does not
133correspond to the remaining headers -- the format of the line
134is described later under
135.Sx SOCKETS .
136.It Li MOUNT
137If the
138.Fl n
139flag was not specified, this header is present and is the
140pathname that the file system the file resides in is mounted on.
141.It Li DEV
142If the
143.Fl n
144flag is specified, this header is present and is the
145number of the device that this file resides in.
146.It Li INUM
147The inode number of the file.
148.It Li MODE
149The mode of the file.
150If the
151.Fl n
152flag is not specified, the mode is printed
153using a symbolic format (see
154.Xr strmode 3 ) ;
155otherwise, the mode is printed
156as an octal number.
157.It Li SZ\&|DV
158If the file is a semaphore,
159prints the current value of the semaphore.
160If the file is not a character or block special, prints the size of
161the file in bytes.
162Otherwise, if the
163.Fl n
164flag is not specified, prints
165the name of the special file as located in
166.Pa /dev .
167If that cannot be
168located, or the
169.Fl n
170flag is specified, prints the major/minor device
171number that the special device refers to.
172.It Li R/W
173This column describes the access mode that the file allows.
174The letter ``r'' indicates open for reading;
175the letter ``w'' indicates open for writing.
176This field is useful when trying to find the processes that are
177preventing a file system from being down graded to read-only.
178.It Li NAME
179If filename arguments are specified and the
180.Fl f
181flag is not, then
182this field is present and is the name associated with the given file.
183Normally the name cannot be determined since there is no mapping
184from an open file back to the directory entry that was used to open
185that file.
186Also, since different directory entries may reference
187the same file (via
188.Xr ln 1 ) ,
189the name printed may not be the actual
190name that the process originally used to open that file.
191.El
192.Sh SOCKETS
193The formatting of open sockets depends on the protocol domain.
194In all cases the first field is the domain name, the second field
195is the socket type (stream, dgram, etc), and the third is the socket
196flags field (in hex).
197The remaining fields are protocol dependent.
198For tcp, it is the address of the tcpcb, and for udp, the inpcb (socket pcb).
199For unix domain sockets, its the address of the socket pcb and the address
200of the connected pcb (if connected).
201Otherwise the protocol number and address of the socket itself are printed.
202The attempt is to make enough information available to
203permit further analysis without duplicating
204.Xr netstat 1 .
205.Pp
206For example, the addresses mentioned above are the addresses which the
207.Dq Li netstat -A
208command would print for tcp, udp, and unixdomain.
209Note that since pipes are implemented using sockets, a pipe appears as a
210connected unix domain stream socket.
211A unidirectional unix domain socket indicates the direction of flow with
212an arrow (``<-'' or ``->''), and a full duplex socket shows a double arrow
213(``<->'').
214.Sh SEE ALSO
215.Xr netstat 1 ,
216.Xr nfsstat 1 ,
217.Xr procstat 1 ,
218.Xr ps 1 ,
219.Xr sockstat 1 ,
220.Xr systat 1 ,
221.Xr tcp 4 ,
222.Xr unix 4 ,
223.Xr iostat 8 ,
224.Xr pstat 8 ,
225.Xr vmstat 8
226.Sh HISTORY
227The
228.Nm
229command appeared in
230.Bx 4.3 tahoe .
231.Sh BUGS
232Since
233.Nm
234takes a snapshot of the system, it is only correct for a very short period
235of time.
236