如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
当前回答
我们可以通过简单地重新启动IIS来避免这种情况,使用下面的命令:
IISRESET
其他回答
对于Windows用户,您可以使用CurrPorts工具轻松地杀死正在使用的端口:
我在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.
使用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
如果你使用powershell 7+,这对我有用。只需在$PROFILE文件中添加此函数。
function killport([parameter(mandatory)] [string] $uport){
if($upid = (Get-NetTCPConnection -LocalPort $uport -ErrorAction Ignore).OwningProcess){kill $upid}
}
然后简单地使用killport 8080
或者如果你只喜欢命令,你可以试试这个:
kill $(Get-NetTCPConnection -LocalPort 8761 -ErrorAction Ignore).OwningProcess
第一步(与KavinduWije所写的接受答案相同):
netstat -ano | findstr:yourPortNumber
第2步更改为:
tskill typeyourPIDhere
注意:taskkill在某些git bash终端中不起作用