如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
当前回答
用于命令行:
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
其他回答
简单的CMD工作我。容易记住
找到你想杀死的端口号并运行下面的CMD
npx kill-port 8080
完成端口后停止并得到此消息
npx: installed 3 in 13.796s
Process on port 8080 killed
在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
如果你想使用Python:检查是否可以在Python中杀死正在监听特定端口的进程,例如8080?
Smunk给出的答案很好。我在这里重复他的密码:
from psutil import process_iter
from signal import SIGTERM # or SIGKILL
for proc in process_iter():
for conns in proc.connections(kind='inet'):
if conns.laddr.port == 8080:
proc.send_signal(SIGTERM) # or SIGKILL
continue
我们可以通过简单地重新启动IIS来避免这种情况,使用下面的命令:
IISRESET
如果你可以在Windows上使用PowerShell,你只需要:
Get-Process -Id (Get-NetTCPConnection -LocalPort "8080").OwningProcess | Stop-Process