Created
June 11, 2018 13:06
-
-
Save zwhitchcox/dc05e89567c0bdb1e50a59c8c6873796 to your computer and use it in GitHub Desktop.
Force kill process by port in one command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# force kill process by port | |
# Usage: "force-kill PORT" | |
sudo netstat -tulnp | grep "$1" | sed -r -e "s/.*LISTEN\\s+([0-9]+).*/\1/" | xargs sudo kill -9 |
@zwhitchcox, I think this is the same thing as fuser $PORT/tcp --kill
except without the usual shellscript bugs or need for sudo
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your version could match multiple ports. Using the input
80
would kill the processes for80
and8080
.sudo netstat -tulnp | grep -E ":$1 .*" | grep -Eo '[^/]+$' | xargs sudo kill -9