#!/usr/bin/python
#
# kill 'em all !
#    By William Stein (was@math.harvard.edu)
# 

import os, sys
if len(sys.argv) == 1:
    print "Usage: %s [options to kill] word "%sys.argv[0]
    print "Kills every process whose ps line contains word."
    sys.exit(0)

n = len(sys.argv)
cmd = sys.argv[n-1]
options = " ".join(sys.argv[1:n-1])

x = os.popen("ps ax").read()
if len(x) <= 1:
    sys.exit(0)
    
for y in x.split("\n"):
    if y.find(sys.argv[0]) != -1 and y.find("python") != -1:
        continue
    if y.find(cmd) == -1:
        continue
    s = "kill %s %s"%(options,y.split()[0])
    print s
    os.system(s)

