Created
July 13, 2014 04:35
-
-
Save allex/8b399a93749703acd780 to your computer and use it in GitHub Desktop.
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 | |
# ================================================ | |
# Description: killport.sh | |
# GistID: 8b399a93749703acd780 | |
# GistURL: https://gist.github.com/allex/8b399a93749703acd780 | |
# Last Modified: Sun Aug 10, 2014 12:22PM | |
# Author: Allex Wang ([email protected]) | |
# ================================================ | |
port=$1 | |
if [[ -z "${port}" ]] && [[ -f /root/.bin/lsresin.sh ]]; then | |
. /root/.bin/lsresin.sh | |
fi | |
while [[ -z "${port}" ]]; do | |
read -p "Please type the port you wanna kill (q to exit): " port | |
done | |
[ "${port}" = "q" ] && exit 0; | |
PID="" | |
case "`uname `" in | |
Linux*) PID=`lsof -t -i:${port}` ;; | |
Darwin*) PID=`lsof -i -n -P | grep ":${port} (LISTEN)" | awk '{print $2}'` ;; | |
esac | |
if [ -n "$PID" ]; | |
then | |
kill -9 $PID && echo "process with pid: ${PID} on port ${port} had killed success!" | |
else | |
echo "The specific process with port '${port}' not found. exit"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment