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

例如:localhost:8080


当前回答

如果你可以在Windows上使用PowerShell,你只需要:

Get-Process -Id (Get-NetTCPConnection -LocalPort "8080").OwningProcess | Stop-Process

其他回答

如果你可以在Windows上使用PowerShell,你只需要:

Get-Process -Id (Get-NetTCPConnection -LocalPort "8080").OwningProcess | Stop-Process

Windows 10/11默认工具:

第一步:

以管理员身份打开Windows PowerShell

第二步:

查找8080端口的PID (ProcessID):

netstat -aon | findstr 8080

TCP 0.0.0.0:8080 0.0.0.0:0 listen 77777

第三步:

杀死僵尸进程:

taskkill /f /pid 77777

“77777”是你的PID

打开命令提示符并发出下面的命令

netstat -ano|findstr "PID :8888"

输出将显示占用端口的进程id

发出下面的命令杀死PID

taskkill /pid 8912 /f

您将收到如下输出

SUCCESS: The process with PID 8860 has been terminated.

用于命令行:

for /f "tokens=5" %a in ('netstat -aon ^| find ":8080" ^| find "LISTENING"') do taskkill /f /pid %a

用于蝙蝠档案:

for /f "tokens=5" %%a in ('netstat -aon ^| find ":8080" ^| find "LISTENING"') do taskkill /f /pid %%a

在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