bash - How to find processes based on port and kill them all? -


find processes based on port number , kill them all.

ps -efl | grep port_number | kill -9 process_found_previously 

how complete last column?

the problem ps -efl | grep port_number port_number may match other columns in output of ps (date, time, pid, ...). potential killing spree if run root!

i instead :

port_number=1234 lsof -i tcp:${port_number} | awk 'nr!=1 {print $2}' | xargs kill  

breakdown of command

  • (lsof -i tcp:${port_number}) -- list processes listening on tcp port
  • (awk 'nr!=1 {print $2}') -- ignore first line, print second column of each line
  • (xargs kill) -- pass on results argument kill. there may several.

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -