首页 文章

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

提问于
浏览
212

如何删除已分配给端口的当前进程/应用程序? (例如: - localhost:8080)

10 回答

  • 56

    Step 1

    以管理员身份运行命令行 . 然后运行下面提到的命令 . 在 yourPortNumber 中键入您的端口号

    netstat -ano | findstr:yourPortNumber

    红色圆圈区域显示PID(进程标识符)

    Step 2

    然后在识别PID后执行此命令 .

    taskkill / PID typeyourPIDhere / F.

    附:再次运行第一个命令以检查进程是否仍然可用 . 如果进程成功结束,您将获得空行 .

  • 1

    第1步(同样是answer所接受的answer):

    netstat -ano | findstr:yourPortNumber

    第2步更改为:

    tskill typeyourPIDhere
    

    这是因为 taskkill 在某些git bash命令中无效

  • 0

    If you are using GitBash

    第一步:

    netstat -ano | findstr :8080
    

    第二步:

    taskkill /PID typeyourPIDhere /F
    

    /F 强制终止该过程)

  • 0

    Windows PowerShell 版本1或更高版本中停止端口3000上的进程类型:

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


    正如@morganpdx所建议的那样,这是一个更好的PowerShell-ish,更好的版本:

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

  • 7

    用于命令行:

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

    用于bat文件:

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

    如果你想用python做它:check Is possible in python kill process which is running on specific port, for example 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
    
  • 69

    对于Windows用户,您可以使用CurrPorts工具轻松杀死正在使用的端口
    enter image description here

  • 516

    我们可以通过使用bellow命令简单地重新启动IIS来避免这种情况 .

    IISRESET

  • 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
    
  • 2

    我在运行zookeeper @windows,无法阻止使用zookeeper-stop.sh在2181端口运行的动物园管理员,所以尝试了这个双斜杠“//”方法来taskkill . 有效

    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.
    

相关问题