Problem with ps -efl | grep PORT_NUMBER ps -efl | grep PORT_NUMBER is that PORT_NUMBER can also match other columns in ps output (date, time, pid, ...). Potential kill on root!
I would do this instead:
PORT_NUMBER=1234 lsof -i tcp:${PORT_NUMBER} | awk 'NR!=1 {print $2}' | xargs kill
Team Breakdown
- (
lsof -i tcp:${PORT_NUMBER} ) - a list of all processes that are listening on this tcp port - (
awk 'NR!=1 {print $2}' ) - ignore the first row, print the second column of each row - (
xargs kill ) - pass the results as an argument to kill . There may be several.
Shawn Chin Feb 18 '11 at 16:31 2011-02-18 16:31
source share