Created
December 21, 2015 06:47
-
-
Save kdheepak/46d84b9085ce5b720626 to your computer and use it in GitHub Desktop.
Clear port
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
#!/usr/bin/env python | |
import sys | |
import subprocess | |
def find_pid(port): | |
pid = subprocess.call(['lsof', '-t', '-i', ":{}".format(port)]) | |
return(pid) | |
def kill_all(list_of_ports): | |
for port in list_of_ports: | |
pid = find_pid(port) | |
subprocess.call(['kill', '-9', str(pid)]) | |
def main(): | |
if len(sys.argv) > 1: | |
kill_all(sys.argv[1:]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment