fix off by one error on fd_lastfile. error in classifying file type.
[unix-history] / usr / src / usr.bin / fstat / fstat.1
CommitLineData
6238cfcd 1.\" Copyright (c) 1987, 1991 Regents of the University of California.
d613fe68 2.\" All rights reserved.
3c3ea40f 3.\"
3c4adc3c 4.\" %sccs.include.redist.roff%
d613fe68 5.\"
4f81f5f0 6.\" @(#)fstat.1 5.12 (Berkeley) %G%
3c3ea40f 7.\"
6238cfcd
CL
8.Dd
9.Dt FSTAT 1
10.Os BSD 4
11.Sh NAME
12.Nm fstat
13.Nd file status
14.Sh SYNOPSIS
15.Nm fstat
16.Op Fl fnv
c6e70268
KB
17.Op Fl M Ar core
18.Op Fl N Ar system
6238cfcd
CL
19.Op Fl u Ar user
20.Op Ar filename...
21.Sh DESCRIPTION
22.Nm Fstat
3c3ea40f 23identifies open files.
90efe901
MT
24A file is considered open by a process if it was explicitly opened,
25is the working directory, root directory, active pure text, or kernel
26trace file for that process.
3c3ea40f 27If no options are specified,
6238cfcd 28.Nm fstat
90efe901 29reports on all open files in the system.
6238cfcd 30.Pp
3c3ea40f 31Options:
6238cfcd
CL
32.Bl -tag -width Ds
33.It Fl f
34If additional filename arguments are present, restrict examination to files
35open in the same filesystem as the named file arguments.
36For example, to find all files open in the filesystem where the
37directory
38.Pa /usr/src
39resides, type
40.Dq Li fstat -f /usr/src .
c6e70268
KB
41.It Fl M
42Extract values associated with the name list from the specified core
43instead of the default
44.Pa /dev/kmem .
45.It Fl N
46Extract the name list from the specified system instead of the default
47.Pa /vmunix .
6238cfcd 48.It Fl n
90efe901
MT
49Numerical format. Print the device number (maj,min) of the filesystem
50the file resides in rather than the mount point name; for special
51files, print the
52device number that the special device refers to rather than the filename
6238cfcd
CL
53in
54.Pa /dev ;
55and print the mode of the file in octal instead of symbolic form.
56.It Fl p
57Report all files open by the specified process.
58.It Fl u
59Report all files open by the specified user.
60.It Fl v
90efe901
MT
61Verbose mode. Print error messages upon failures to locate particular
62system data structures rather than silently ignoring them. Most of
6238cfcd
CL
63these data structures are dynamically created or deleted and it is
64possible for them to disappear while
65.Nm fstat
66is running. This
90efe901 67is normal and unavoidable since the rest of the system is running while
6238cfcd
CL
68.Nm fstat
69itself is running.
70.It Ar filename ...
d613fe68 71Restrict reports to the specified files.
6238cfcd
CL
72.El
73.Pp
c54894dd 74The following fields are printed:
6238cfcd
CL
75.Bl -tag -width MOUNT
76.It Li USER
90efe901 77The username of the owner of the process (effective uid).
6238cfcd 78.It Li CMD
3c3ea40f 79The command name of the process.
6238cfcd 80.It Li PID
3c3ea40f 81The process id.
6238cfcd 82.It Li FD
90efe901
MT
83The file number in the per-process open file table or one of the following
84special names:
6238cfcd
CL
85.Pp
86.Bd -ragged -offset indent -compact
87text - pure text inode
88wd - current working directory
89root - root inode
90tr - kernel trace file
91.Ed
92.Pp
90efe901 93If the file number is followed by an asterisk (``*''), the file is
6238cfcd
CL
94not an inode, but rather a socket,
95.Tn FIFO ,
96or there is an error.
90efe901
MT
97In this case the remainder of the line doesn't
98correspond to the remaining headers -- the format of the line
6238cfcd
CL
99is described later under
100.Sx Sockets .
101.It Li MOUNT
102If the
103.Fl n
104flag wasn't specified, this header is present and is the
90efe901 105pathname that the filesystem the file resides in is mounted on.
6238cfcd
CL
106.It Li DEV
107If the
108.Fl n
109flag is specified, this header is present and is the
90efe901 110major/minor number of the device that this file resides in.
6238cfcd 111.It Li INUM
3c3ea40f 112The inode number of the file.
6238cfcd
CL
113.It Li MODE
114The mode of the file. If the
115.Fl n
116flag isn't specified, the mode is printed
117using a symbolic format (see
118.Xr strmode 3 ) ;
119otherwise, the mode is printed
90efe901 120as an octal number.
6238cfcd 121.It Li SZ\&|DV
90efe901 122If the file is not a character or block special, prints the size of
6238cfcd
CL
123the file in bytes. Otherwise, if the
124.Fl n
125flag is not specified, prints
126the name of the special file as located in
127.Pa /dev .
128If that cannot be
129located, or the
130.Fl n
131flag is specified, prints the major/minor device
90efe901 132number that the special device refers to.
6238cfcd
CL
133.It Li NAME
134If filename arguments are specified and the
135.Fl f
136flag is not, then
90efe901
MT
137this field is present and is the name associated with the given file.
138Normally the name cannot be determined since there is no mapping
139from an open file back to the directory entry that was used to open
140that file. Also, since different directory entries may reference
6238cfcd
CL
141the same file (via
142.Xr ln 2 ) ,
143the name printed may not be the actual
90efe901 144name that the process originally used to open that file.
6238cfcd
CL
145.El
146.Sh SOCKETS
c54894dd
KB
147The formating of open sockets depends on the protocol domain.
148In all cases the first field is the domain name, the second field
3c3ea40f 149is the socket type (stream, dgram, etc), and the third is the socket
c54894dd
KB
150flags field (in hex).
151The remaining fields are protocol dependent.
152For tcp, it is the address of the tcpcb, and for udp, the inpcb (socket pcb).
153For unix domain sockets, its the address of the socket pcb and the address
154of the connected pcb (if connected).
155Otherwise the protocol number and address of the socket itself are printed.
90efe901
MT
156The attempt is to make enough information available to
157permit further analysis without duplicating
6238cfcd
CL
158.Xr netstat 1 .
159.Pp
c54894dd 160For example, the addresses mentioned above are the addresses which the
6238cfcd
CL
161.Dq Li netstat -A
162command would print for tcp, udp, and unixdomain.
c54894dd
KB
163Note that since pipes are implemented using sockets, a pipe appears as a
164connected unix domain stream socket.
165A unidirectional unix domain socket indicates the direction of flow with
166an arrow (``<-'' or ``->''), and a full duplex socket shows a double arrow
167(``<->'').
6238cfcd 168.Sh BUGS
c54894dd 169Since
6238cfcd 170.Nm fstat
c54894dd
KB
171takes a snapshot of the system, it is only correct for a very short period
172of time.
6238cfcd
CL
173.Sh SEE ALSO
174.Xr netstat 1 ,
c6e70268 175.Xr nfsstat 1 ,
6238cfcd
CL
176.Xr ps 1 ,
177.Xr systat 1 ,
c6e70268
KB
178.Xr vmstat 1 ,
179.Xr iostat 8 ,
6238cfcd
CL
180.Xr pstat 8
181.Sh HISTORY
182The
183.Nm
184command appeared in
4f81f5f0 185.Bx 4.3 tahoe .