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

后端 未结 20 2062
陌清茗
陌清茗 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:27

    In Windows PowerShell version 1 or later to stop a process on port 3000 type:

    Stop-Process (,(netstat -ano | findstr :3000).split() | foreach {$[$.length-1]}) -Force


    As suggested by @morganpdx here`s a more PowerShell-ish, better version:

    Stop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force

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

    One line solution using GitBash:

     tskill `netstat -ano | grep LISTENING | findstr :8080 | sed -r 's/(\s+[^\s]+){4}(.*)/\1/'`
    

    Replace 8080 with the port your server is listening to.

    If you need to use it often, try adding to your ~/.bashrc the function:

    function killport() {
            tskill `netstat -ano | findstr LISTENING | findstr :$1 | sed -r 's/^(\s+[^\s]+){4}(\d*)$/\1/'`
    }
    

    and simply run

    killport 8080
    
    0 讨论(0)
提交回复
热议问题