如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
当前回答
使用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
其他回答
最简单的解决办法,也是我唯一记得的办法:
在Windows Powershell中
假设我们想停止端口8080上的进程
获取过程:
netstat -ano | findstr :8080
停止进程
stop-process 82932
我们可以通过简单地重新启动IIS来避免这种情况,使用下面的命令:
IISRESET
以管理员身份运行cmd。然后在里面输入这个代码。
netstat -ano | findstr :<8080>
然后您可以看到PID在端口上运行。然后复制PID编号。(PID是帮助识别硬件产品或已注册软件产品的唯一数字。)并键入下面的代码行和按enter。
taskkill /PID <Enter the copied PID Number> /F
如果您已经知道端口号,那么向进程发送软件终止信号(SIGTERM)可能就足够了:
kill $(lsof -t -i :PORT_NUMBER)
使用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