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

后端 未结 20 2484
陌清茗
陌清茗 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: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
    

提交回复
热议问题