mmnoyw
Last Updated: February 25, 2016
·
1.185K
· kevinsuttle
Kevin suttle

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

Say Thanks
Respond

2 Responses
Add your response

11805
Supergotchi normal

Useless use of grep, awk does the same thing :)

lsof -i TCP:$1 | awk '/LISTEN/{print $2}' | xargs kill -9

over 1 year ago ·
15057
D3fe491fd07d1bbce780696b3c468f4c

Thanks @kevinsuttle & @sejeff!

over 1 year ago ·
Filed Under