How to find the process in Linux and MacOS that has a port opened

Michael Roma on Nov 29, 2019

First, run the following command to show processes running with the given port opened:

lsof -i tcp:3001

This will output something like this:

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    4320 mroma   19u  IPv6  37934      0t0  TCP *:3001 (LISTEN)

Once you find the process, use the command below to kill it:

kill 4320

You can use the following command to find and kill at the same time by parsing the results with awk

lsof -i tcp:3000 | awk ‘{system(“kill -9 ” $2)}’