mmnoyw
Last Updated: February 25, 2016
·
1.219K
· kevinsuttle

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

2 Responses
Add your response

11805

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

Thanks @kevinsuttle & @sejeff!

over 1 year ago ·
Filed Under