How can I remove the current process/application which is already assigned to a port?
For example: localhost:8080
You can do by run a bat file:
@ECHO OFF
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr "9797" ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine
:SkipLine
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%
PAUSE
With Windows 10 default tools:
Open Windows PowerShell as Administrator
Find PID (ProcessID) for port 8080:
netstat -aon | findstr 8080
TCP 0.0.0.0:8080 0.0.0.0:0 LISTEN 77777
Kill the zombie process:
taskkill /f /pid 77777
where "77777" is your PID
I was running zookeeper on Windows and wasn't able to stop ZooKeeper running at 2181 port using zookeeper-stop.sh, so tried this double slash "//" method to taskkill. It worked
1. netstat -ano | findstr :2181
TCP 0.0.0.0:2181 0.0.0.0:0 LISTENING 8876
TCP [::]:2181 [::]:0 LISTENING 8876
2.taskkill //PID 8876 //F
SUCCESS: The process with PID 8876 has been terminated.
If you can use PowerShell on Windows you just need :
Get-Process -Id (Get-NetTCPConnection -LocalPort "8080").OwningProcess | Stop-Process
We can avoid this by simple restarting IIS, using the below command:
IISRESET
netstat -ano | findstr :PORT
kill PI