Find processes based on port number and kill them all.
ps -efl | grep PORT_NUMBER | kill -9 process_found_previously
how to complete the last column?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem with
ps -efl | grep PORT_NUMBERis thatPORT_NUMBERmay match other columns in the output ofpsas well (date, time, pid, …). A potential killing spree if run by root!I would do this instead :
Breakdown of command
lsof -i tcp:${PORT_NUMBER}) — list all processes that is listening on that tcp portawk 'NR!=1 {print $2}') — ignore first line, print second column of each linexargs kill) — pass on the results as an argument tokill. There may be several.