How to find which program or process is listening on a certain port in Linux?

My program reports that the port is already used.

How to find which program or process is listening on a certain port in Linux?

You can use netstat to do this. netstat can print network connections.

For example, to find which program is listing on port 9999

netstat -pln | grep 9999

You will need to use sudo to get more details, such as process names that are now owned by you.

sudo netstat -pln | grep 9999

Here, p makes netstat print process name, ‘l’ means “listening” and ‘n’ means numerical addresses instead of trying to determine symbolic host, port or user names.

If you are sure that the programming is using TCP or UDP, you can also add option t or u to filter out only TCP and UDP connections like

sudo netstat -ptln | grep 9999
sudo netstat -puln | grep 9999

For more details, please check netstat manual.

Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *