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
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/93128/supergotchi_normal.png)
Useless use of grep, awk does the same thing :)
lsof -i TCP:$1 | awk '/LISTEN/{print $2}' | xargs kill -9
over 1 year ago
·
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/29214/d3fe491fd07d1bbce780696b3c468f4c.jpeg)
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#