A function to find and kill processes running on a certain port
searchAndDestroy() {
lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9
echo "Port" $1 "found and killed."
}
Usage: searchAndDestroy 3000
Note: this was my first crack at this. Help me improve it! https://github.com/kevinSuttle/dotfiles/pulls
Written by Kevin Suttle
Related protips
2 Responses
Useless use of grep, awk does the same thing :)
lsof -i TCP:$1 | awk '/LISTEN/{print $2}' | xargs kill -9
over 1 year ago
·
Thanks @kevinsuttle & @sejeff!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#