#!/usr/bin/env python3

import re
import os
import os.path
import sys
import signal

""" ensure that there are enough command line arguments to parse """
if len(sys.argv) < 2:
    print("Usage: 86.py  PROCESS");
    exit();

# 86 -  (version  3 Apr 10)
# kill any command containing $1 

USERID = os.getlogin()

if USERID == "root":
    print '86: >>> WARNING - this command may not be run as root'
else:
    try:
        import WMI

        # WINDOWS
        # from: http://mail.python.org/pipermail/python-win32/2003-December/001482.html
        processes = WMI.InstancesOf('Win32_Process')
    except:
        # UNIX
        # from: http://stackoverflow.com/questions/1091327/processlist
        for p, c in [x.lstrip(' ').rstrip('\n').split(' ', 1)
            for x in os.popen('ps -u ' + USERID + ' -o pid,fname')]:
                if p != "PID" and re.search(sys.argv[1], c):
                    os.kill(int(p), signal.SIGKILL)
    #print processes
