How do I kill the process currently using a port on localhost in Windows?

后端 未结 20 2060
陌清茗
陌清茗 2020-11-22 11:37

How can I remove the current process/application which is already assigned to a port?

For example: localhost:8080

相关标签:
20条回答
  • 2020-11-22 12:13

    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
    
    0 讨论(0)
  • 2020-11-22 12:14

    With Windows 10 default tools:

    • Step one:

    Open Windows PowerShell as Administrator

    • Step two:

    Find PID (ProcessID) for port 8080:

    netstat -aon | findstr 8080
    

    TCP 0.0.0.0:8080 0.0.0.0:0 LISTEN 77777

    • Step three:

    Kill the zombie process:

    taskkill /f /pid 77777
    

    where "77777" is your PID

    0 讨论(0)
  • 2020-11-22 12:14

    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.
    
    0 讨论(0)
  • 2020-11-22 12:14

    If you can use PowerShell on Windows you just need :

    Get-Process -Id (Get-NetTCPConnection -LocalPort "8080").OwningProcess | Stop-Process
    
    0 讨论(0)
  • 2020-11-22 12:14

    We can avoid this by simple restarting IIS, using the below command:

    IISRESET
    
    0 讨论(0)
  • 2020-11-22 12:18
    netstat -ano | findstr :PORT
    kill PI
    
    0 讨论(0)
提交回复
热议问题