How to find the process that is using the port

Sometimes, when developing multiple applications at once or trying to demonstrate, I end up running multiple programs on different ports of the computer:3000,3001,1313, and many more.

If I don't pay close attention, I might forget which application is running on a specific port.

How do we determine which program is listening on the port?

ThislsofCommands can help us do this!

Run

lsof -i :1313

Will tell me the command that’s currently listening on port 1313:

COMMAND  PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
hugo    8698 fla 4764u  IPv4 0xc72ca30d18e45ef9      0t0  TCP localhost:bmc_patroldb (LISTEN)

In this case it’s the hugo command, with PID 8698.

If I want to terminate that program, I can just run kill 8698.

Download my free Linux Commands Handbook


More cli tutorials: