Skip to content

Instantly share code, notes, and snippets.

@mcrisc
Created November 6, 2009 11:07
Show Gist options
  • Save mcrisc/227930 to your computer and use it in GitHub Desktop.
Save mcrisc/227930 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# kills the process holding the TCP port passed as a command line argument
import subprocess
import os, sys
if len(sys.argv) < 2:
print "Missing argument: TCP port"
sys.exit(1)
port = sys.argv[1]
p = subprocess.Popen(("fuser -n tcp %s" % port).split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pid = p.communicate()[0].strip()
if pid:
print "killing %s" % pid
os.system("kill -9 %s" % pid)
#!/usr/bin/ruby
# kills the process holding the TCP port passed as a command line argument
if not ARGV[0]
puts "Missing argument: TCP port"
exit!(1)
end
port = ARGV[0]
IO.popen("fuser -n tcp #{port}") do |p|
if p.gets =~ /.*?(\d+)$/
puts "killing #{$1}"
IO.popen("kill -9 #{$1}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment