Find the process using a given port

This article shows how to find the process using a given port or range of ports on *nix systems.
 
Many a times when running socket based applications you will find the application failing with socket bind exception with a message saying address is already in use. That indicates that some other process is already using the port you are trying to use.
 
Without some useful utilities it would be difficult to find who is using your port. On *nix systems, there comes a command called lsof which can help you out. It may not always be installed out of the box in which case you may explicitly install it. To find the process that is using your port run the following command: 

 
Below is a sample output showing the pid of the process that is using port number 17565.

 
You may also specify a protocol filter TCP or UDP ahead of the port number as follows.

 
You may also specify a port range instead of exact port numbers. It will list all the processes that are using the given range of ports.

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Next article

Find files containing my text