How do I kill the process currently using a port on localhost in Windows?

后端 未结 20 2059
陌清茗
陌清茗 2020-11-22 11:37

How can I remove the current process/application which is already assigned to a port?

For example: localhost:8080

相关标签:
20条回答
  • 2020-11-22 12:03

    I know that is really old question, but found pretty easy to remember, fast command to kill app that are using port.

    Requirements: npm@5.2.0^ version

    npx kill-port 8080
    

    You can also read more about kill-port here: https://www.npmjs.com/package/kill-port

    0 讨论(0)
  • If you are using GitBash

    Step one:

    netstat -ano | findstr :8080
    

    Step two:

    taskkill /PID typeyourPIDhere /F 
    

    (/F forcefully terminates the process)

    0 讨论(0)
  • 2020-11-22 12:06

    the first step

    netstat -vanp tcp | grep 8888
    

    example

    tcp4     0      0    127.0.0.1.8888   *.*    LISTEN      131072 131072  76061    0
    tcp46    0      0    *.8888           *.*    LISTEN      131072 131072  50523    0
    

    the second step: find your PIDs and kill them

    in my case

    sudo kill -9 76061 50523
    
    0 讨论(0)
  • 2020-11-22 12:10

    Step 1 (same is in accepted answer written by KavinduWije):

    netstat -ano | findstr :yourPortNumber
    

    Change in Step 2 to:

    tskill typeyourPIDhere 
    

    Note: taskkill is not working in some git bash terminal

    0 讨论(0)
  • 2020-11-22 12:11

    In case you want to do it using Python: check Is it possible in python to kill process that is listening on specific port, for example 8080?

    The answer from Smunk works nicely. I repeat his code here:

    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
    
    0 讨论(0)
  • 2020-11-22 12:12

    For Windows users, you can use the CurrPorts tool to kill ports under usage easily:

    0 讨论(0)
提交回复
热议问题