1834126 Members
2201 Online
110064 Solutions
New Discussion

lsof question

 
SOLVED
Go to solution
Hunki
Super Advisor

lsof question


I need to check for files which are being used by a particular port. How do I do that through lsof.

thanks
6 REPLIES 6
Jov
Honored Contributor
Solution

Re: lsof question

From the lsof manpages

-i [i] This option selects the listing of files any of whose Internet
address matches the address specified in i. If no address is
specified, this option selects the listing of all Internet and
x.25 (HP-UX) network files.

If -i4 or -i6 is specified with no following address, only
files of the indicated IP version, IPv4 or IPv6, are dis-
played. (An IPv6 specification may be used only if the
dialects supports IPv6, as indicated by ``[46]'' and
``IPv[46]'' in lsof's -h or -? output.) Sequentially speci-
fying -i4, followed by -i6 is the same as specifying -i, and
vice-versa. Specifying -i4, or -i6 after -i is the same as
specifying -i4 or -i6 by itself.

Multiple addresses (up to a limit of 100) may be specified
with multiple -i options. (A port number or service name
range is counted as one address.) They are joined in a single
ORed set before participating in AND option selection.

An Internet address is specified in the form (Items in square
brackets are optional.):

[46][protocol][@hostname|hostaddr][:service|port]

where:
46 specifies the IP version, IPv4 or IPv6
that applies to the following address.
'6' may be be specified only if the UNIX
dialect supports IPv6. If neither '4' nor
'6' is specified, the following address
applies to all IP versions.
protocol is a protocol name - TCP or UDP.
hostname is an Internet host name. Unless a
specific IP version is specified, open
network files associated with host names
of all versions will be selected.
hostaddr is a numeric Internet IPv4 address in
dot form; or an IPv6 numeric address in
colon form, enclosed in brackets, if the
UNIX dialect supports IPv6. When an IP
version is selected, only its numeric
addresses may be specified.
service is an /etc/services name - e.g., smtp -
or a list of them.
port is a port number, or a list of them.

Can you try something like 'lsof -i :49152' or 'lsof -i @:49152'

The grep for the filename.


Jov
A. Clay Stephenson
Acclaimed Contributor

Re: lsof question

More accurately you find the process that is using a port and the PID can then lead you to the files.

For example to find all the processes associated with port 23 (telnet), you can specify either the port number or name

lsof -i :23
or
lsof -i :telnet

then when the process id is displayed:
lsof -p PID

and you have your files.
If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: lsof question

Files cannot be be opened/used by a particular port. Only a process [listening on a particular port] can have open files.
Jov
Honored Contributor

Re: lsof question

I was think of the executable as the file, but Clay is spot on.


Jov
Hunki
Super Advisor

Re: lsof question


The output I got from lsof is similar to netstat -an

java 5987 prod 75u inet 0x300160a96c0 0t0 TCP *:10222 (LISTEN)

The Java developers say that the port 10222 is not freed up and is in listening mode , though I was of the view that the port is free and is listening .

The argument they gave me was that CORBA ORB is initialized and passes this port to a request from another server and the connection is made and once the connection is released then the port is not in listening mode and should not come up in the listing of netstat or the lsof as its coming up now.( above output )

Has anybody encountered this before. Any suggestions are welcome.
Hunki
Super Advisor

Re: lsof question


More clear explanation from Java Devs :

The port should be in listening mode once the ORB has been reinitialized not before that.

Anybody faced this with CORBA ORB or any other application.