根据端口号查找进程并将其全部杀死。
ps -efl | grep PORT_NUMBER | kill -9 process_found_previously
如何完成最后一栏?
... | awk '{ print $4 }' | xargs kill -9
please test with "echo" instead of "kill" before running
The problem with ps -efl | grep PORT_NUMBER is that PORT_NUMBER may match other columns in the output of ps as well (date, time, pid, ...). A potential killing spree if run by root!
ps -efl | grep PORT_NUMBER
PORT_NUMBER
ps
I would do this instead :
PORT_NUMBER=1234 lsof -i tcp:${PORT_NUMBER} | awk 'NR!=1 {print $2}' | xargs kill
Breakdown of command
lsof -i tcp:${PORT_NUMBER}
awk 'NR!=1 {print $2}'
xargs kill
kill
Propose to use fuser command:
fuser -k -TERM -n tcp ${PORT_NUMBER}
To kill all processes listening on a particular port, e.g. port 8864
kill -9 $ \`lsof -i:8864 -t\`
Replace 8864 by the port you want.
kill $( lsof -i:6000 -t )
Or if you need permissions:
sudo kill $( sudo lsof -i:6000 -t )
1.) lsof -w -n -i tcp:8080
lsof -w -n -i tcp:8080
2.) kill -9 processId
kill -9 processId
sudo fuser -k 8080/tcp
An easy one to remember.
This syntax is probably much more recent than the date of the question!