Coder's Cat

How to Find Which Process using a Networking Port

2020-06-15

Using netstat and lsof command to show which process using a Port on Mac/Linux

file:img/2020_06_08_how-to-find-which-process-used-a-networking-port.org_20200615_162735.png

netstat

Command netstat will show the most useful statistic data of networking.

netstat -ltnp | grep -w ':8080' 

The above command will display the information related to the networking port of 8080.

These are the detailed meaning of options:

l – let netstat to only show listening sockets.
t – let netstat to display TCP connections.
n – show numerical addresses.
p – enables showing of the process ID and the process name.
grep -w – shows matching of exact string (:80).

Note: On MacOs, we’re stuck with the BSD netstat which will not show you the process ID that is attached to a given port.

So, lsof will be a choice for Mac.

lsof

Command lsof will display all opened files of a process. We could also use it to find which process used a networking port, since TCP/IP sockets use file descriptors.

lsof -i will show which process communicating over the internet.

file:img/2020_06_08_how-to-find-which-process-used-a-networking-port.org_20200615_161636.png


Join my Email List for more insights, It's Free!😋