Linux script to kill process listening on a particular port

Posted by Evgeny on Stack Overflow See other posts from Stack Overflow or by Evgeny
Published on 2010-03-14T23:57:04Z Indexed on 2010/03/14 23:59 UTC
Read the original article Hit count: 206

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about linux

Related posts about bash