How to find which process has occupied a specific port
netstat 1
sudo apt install net-tools
sudo netstat -ltnp
lsof 1
sudo apt install lsof
sudo lsof -i :80
- DON'T forget the
:
before the port number
On Mac specifically: 2
lsof -nP -iTCP:$PORT | grep LISTEN
fuser 1
sudo apt install psmisc
# show a port number is listening by a process number
sudo fuser 3306/tcp
# check the process name by the process number
ps -p [processID] -o comm=
Usability Test
Method | Linux | Mac |
---|---|---|
netstat | ✅ | ❌ |
lsof | ✅ | ✅ |
fuser | ✅ | ❌ |