How to Kill a Port on macOS and Linux

Find port you want to kill. With -i option only processes associated with internet connections will be listed:

lsof -i :<PORT>

Kill the port. With -9 option all processes associated with <PID> will immediately be terminated:

kill -9 <PID>

Example

lsof -i :8080
COMMAND   PID     USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
node    92734 username   23u  IPv6 0xad3ca5a2d5277c7      0t0  TCP *:http-alt (LISTEN)
kill -9 92734

Note that 92734 is PID found in the output of a previous command.

© 2019-2022 Sergei Kriger. All rights reserved.