如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
如何删除已分配给端口的当前进程/应用程序?
例如:localhost: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
其他回答
使用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
用于命令行:
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
netstat -ano | findstr :PORT
kill PI
对于Windows用户,您可以使用CurrPorts工具轻松地杀死正在使用的端口: