Linux script to kill process listening on a particular port
Posted
by Evgeny
on Server Fault
See other posts from Server Fault
or by Evgeny
Published on 2010-03-14T23:57:04Z
Indexed on
2010/03/15
1:19 UTC
Read the original article
Hit count: 467
I have a process that listens on a TCP port (?0003). From time to time it crashes - badly. It stops working, but continues hogging the port for some time, so I can't even restart it. I'm looking to automate this.
What I do right now is:
netstat -ntlp |grep -P "\*\:\d0003"
To see what the PID is and then:
kill -9 <pid>
Does anyone have a script (or EXE for that matter) that would link the two steps together, ie. parse the PID from the first command and pass it to the second?
© Server Fault or respective owner