August 11, 2018

102 words 1 min read

Find and Kill Process Locking on Mac's Specific Port

Find and Kill Process Locking on Mac's Specific Port

It happens multiple times when We running application with spesific port but the port is used and our application failed to start.

Sometimes We don’t know which application using that port. No worries, there’s a handy script for that!

# For example we want to kill a process locking at port 8080

# 1. Using netstat
$ kill -9 $(netstat -vanp tcp | grep 8080 | grep LISTEN | awk '{print $9}')

# 2. Using lsof *(this command may need root permission)*
$ sudo kill -9 $(echo $(lsof -i tcp:8080 | awk '{print $2}') | cut -d' ' -f 2)

Credits: https://stackoverflow.com/questions/3855127