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

例如: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用户,您可以使用CurrPorts工具轻松地杀死正在使用的端口:

让我们自动化!

如果你像我一样经常遇到这个问题,创建一个.bat文件并运行它来结束进程。

创建一个bat文件"killport.bat"

set /P port="Enter port : "
echo showing process running with port %port%

netstat -ano|findstr "PID :%port%"

set /P pid="Enter PID to kill : "

taskkill /pid %pid% /f

set /P exit="Press any key to exit..."

通过双击和运行此文件

输入端口号(然后它将列出带有PID的进程) 输入PID kill

Done

(可选)

设置为path environment,以便您可以从任何地方访问此文件。

你很可能知道如何给env添加一个新路径。但如果你不这样做,你可以这样做

1 / 4

在开始菜单上搜索ENV

2 . 4步

选择环境变量

3 / 4步骤

选择“path”,然后点击编辑按钮

4 / 4步骤

点击“新建”添加。bat文件的存放路径。自从我把它存到…我正在添加这个路径。您的路径将取决于您保存该文件的位置。

打开CMD并测试。请记住,您的文件名将运行此文件的单词。因为我把。bat文件保存为'killport.bat' => 'killport'是运行它的词。

如果你喜欢! 在这里分享你是如何做到的

简单的CMD工作我。容易记住

找到你想杀死的端口号并运行下面的CMD

npx kill-port 8080

完成端口后停止并得到此消息

npx: installed 3 in 13.796s
Process on port 8080 killed

用于命令行:

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