Kill processes listening on specific port
11 March 2022 (Updated 3 August 2025)
On this page
sudo lsof -i tcp:8080 | awk 'NR!=1 {print $2}' | xargs -r kill
lsof -i tcp:8080– list all processes that is listening on TCP port8080awk 'NR!=1 {print $2}'– ignore first line and print second column of each linexargs -r kill– pipe the port numbers as an argument to kill.
Bonus: add shell alias
function killport() {
lsof -i tcp:$1 | awk 'NR!=1 {print $2}' | xargs -r kill
}
Now, you can do killport 8080.
Sources
Tagged:
Unix processes
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment