如何在windows系统中杀死当前使用localhost端口的进程?

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

例如:localhost:8080

解决办法

步骤1

以管理员身份运行命令行。然后运行下面提到的命令。 在你的PortNumber中输入你的端口号。

netstat -ano | findstr :yourPortNumber)

红色圈出的区域显示PID(进程标识符)。

第2步

然后你在确定PID后执行这个命令。

taskkill /PID typeyourPIDhere /F

P.S. 再次运行第一条命令以检查进程是否仍然可用。如果进程成功结束,你会得到空行。

评论(8)

步骤1(同样是在接受的答案中,由KavinduWije撰写):

*gt; netstat -ano | findstr :yourPortNumber

在步骤2中修改为:

tskill typeyourPIDhere 

这是因为taskkill在某些git bash命令中不起作用

评论(8)

**如果你使用的是GitBash,***

步骤一:

netstat -ano | findstr :8080

第二步:

taskkill /PID typeyourPIDhere /F 

(/F强行终止该进程)

评论(2)

使用WINDOWS10默认工具:

步骤1: 以管理员身份打开Windows PowerShell

第2步: 找到8080端口的PID(进程ID)。

netstat -aon | findstr 8080

TCP 0.0.0.0:8080 0.0.0.0:0 LISTEN 77777

第三步: 杀死僵尸的过程。

taskkill /f /pid 77777

其中"7777" 是您的PID

评论(1)

Windows PowerShell版本1或更高版本中,停止3000端口上的进程。

Stop-Process (,(netstat -ano | findstr :3000).split() | foreach {$[$.length-1]}) -Force


按照@morganpdx的建议,这里有一个更像PowerShell的,更好的版本。

Stop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force。

评论(5)

在命令行中使用。

for /f "tokens=5" %a in ('netstat -aon ^| find ":8080" ^| find "LISTENING"') do taskkill /f /pid %a

用于bat-file中。

for /f "tokens=5" %%a in ('netstat -aon ^| find ":8080" ^| find "LISTENING"') do taskkill /f /pid %%a
评论(2)

如果您已经知道了端口号, 那么向进程发送一个软件终止信号 (SIGTERM) 就足够了。

kill $(lsof -t -i :PORT_NUMBER)
评论(1)

对于windows用户,您可以使用[CurrPorts][1]工具轻松杀死正在使用的端口。 [![在此输入图像描述][2]][2]

[1]: https://www.nirsoft.net/utils/cports.html#DownloadLinks [2]: https://i.stack.imgur.com/wSqrm.png

评论(0)

我在运行zookeeper @windows时,无法用zookeeper-stop.sh停止zookeeper在2181端口的运行,所以尝试了双斜线"//" 的方法来杀死任务。 它的工作原理是

     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.
评论(0)

你可以通过运行一个bat文件来实现。

@ECHO OFF                                                                              
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr "9797" ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                   
:SkipLine                                                                              
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%
PAUSE
评论(0)

如果你想用python来做。 查看https://stackoverflow.com/questions/20691258/is-possible-in-python-kill-process-which-is-running-on-specific-port-for-exampl [Smunk][1]的答案很好用。 我在这里重复一下他的代码。

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 

[1]: https://stackoverflow.com/users/905256/smunk

评论(0)

我们可以通过简单的重启IIS来避免这种情况,使用下面的命令。

IISRESET

评论(0)