Created
March 17, 2018 10:30
-
-
Save ajinabraham/35d51deea0aa9aa2b62fcf23d27677c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from psutil import process_iter, NoSuchProcess | |
from signal import SIGTERM, SIGKILL | |
def kill_proxy_process(port): | |
"""Kill 'em all""" | |
for proc in process_iter(): | |
try: | |
pinfo = proc.as_dict() | |
except NoSuchProcess: | |
pass | |
else: | |
if pinfo["connections"]: | |
conns = pinfo["connections"] | |
for conn in conns: | |
if conn.laddr.port == port: | |
proc.send_signal(SIGTERM) | |
proc.send_signal(SIGKILL) | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment