Powershell to kill a program running on port X

Sometimes during development Tomcat will stop responding and won’t gracefully shutdown. I then have to figure out which java process is Tomcat and kill it. Usually the easiest way is to find out which process is using the port Tomcat is running on.

Here is a powershell script that finds all processes running on port 80 and kills them. This assumes the process is listening on which means all IP’s and network interfaces.

netstat -ano | ? {$_ -like "* *"} |
% {
$_ -match "\d+$";
echo $matches[0];
taskkill /F /PID $matches[0]

Leave a Reply