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 argumentkill
. there may several.
Comments
Post a Comment