Find which process is running on a certain port and kill it
- Published on
- Published on
- /2 mins read/––– views
MacOS only
List all the processes by ports with their PIDs
$ sudo lsof -i -P | grep LISTEN
The result should look like this:
rapportd 123 mengke 5u IPv4 0x84512a8572c9xxxx 0t0 TCP *:62003 (LISTEN)
rapportd 123 mengke 6u IPv6 0x84512a857627xxxx 0t0 TCP *:62003 (LISTEN)
mongod 414 mengke 9u IPv4 0x84512a857926xxxx 0t0 TCP localhost:27017 (LISTEN)
Loom 3315 mengke 28u IPv4 0x84512a85785cxxxx 0t0 TCP localhost:11223 (LISTEN)
node 38238 mengke 22u IPv6 0x84512a857627xxxx 0t0 TCP *:5000 (LISTEN)
node 68336 mengke 22u IPv6 0x84512a858bb4xxxx 0t0 TCP *:443 (LISTEN)
The 2nd column is the PID of the process on the port in the last column
Now kill the process in that port by using sudo kill -9 <PID>
$ sudo kill -9 68336
68336
is the PID of the process running on port 443
Check again
$ sudo lsof -i -P | grep LISTEN
rapportd 123 mengke 5u IPv4 0x84512a8572c9xxxx 0t0 TCP *:62003 (LISTEN)
rapportd 123 mengke 6u IPv6 0x84512a857627xxxx 0t0 TCP *:62003 (LISTEN)
mongod 414 mengke 9u IPv4 0x84512a857926xxxx 0t0 TCP localhost:27017 (LISTEN)
Loom 3315 mengke 28u IPv4 0x84512a85785cxxxx 0t0 TCP localhost:11223 (LISTEN)
node 38238 mengke 22u IPv6 0x84512a857627xxxx 0t0 TCP *:5000 (LISTEN)
The process on port 443
is already stopped!
Cheers
Share: