如何删除已分配给端口的当前进程/应用程序?

例如:localhost:8080


当前回答

第一步(与KavinduWije所写的接受答案相同):

netstat -ano | findstr:yourPortNumber

第2步更改为:

tskill typeyourPIDhere 

注意:taskkill在某些git bash终端中不起作用

其他回答

最简单的解决办法,也是我唯一记得的办法:

在Windows Powershell中

假设我们想停止端口8080上的进程

获取过程:

netstat -ano | findstr :8080

停止进程

stop-process 82932

使用GitBash的一行解决方案:

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

将8080替换为服务器正在侦听的端口。

如果您需要经常使用它,请尝试添加到~/。Bashrc函数:

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

然后简单地运行

killport 8080

在Windows PowerShell版本1或更高版本中停止端口3000上的进程:

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


根据@morganpdx的建议,这里有一个更像powershell的更好的版本:

Stop-Process -Id (get - netttcpconnection -LocalPort 3000)。OwningProcess force

如果您已经知道端口号,那么向进程发送软件终止信号(SIGTERM)可能就足够了:

kill $(lsof -t -i :PORT_NUMBER)

我在Windows上运行zookeeper,无法使用zookeeper-stop.sh停止在2181端口运行的zookeeper,所以尝试了这个双斜线“//”方法来kill任务。它工作

     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.