July 22, 2024 /
1 min /
#bash
#terminal
#networking
Kill the running application using the port number
When I close my applications running in the terminal, sometimes ports don’t die and killall node
doesn’t work.
You can use kill
to force close the port.
sudo kill $(sudo lsof -t -i:{PORT})
You can then assign aliases to simplify usage.
alias killport="killport_function"killport_function (){ sudo kill $(sudo lsof -t -i:$1)}
Put the above code in your ~/.zshrc
file and run source ~/.zshrc
. You can now use it as follows.
killport 3000