#!/usr/bin/env python
import os

command = "kqedKeepAlive.py"

def getPID():
  pidFile = os.popen("ps x | grep -i '%s'" % command[:32], 'r',-1)
  pids = pidFile.readlines()
  pid = None
  if len(pids) > 0:
    for entry in pids:
      if "grep" not in entry:
        pid = entry.split()[0]
        break
  return pid

# Kill existing:
while 1:
  pid = getPID()
  if pid == None:
    break
  else:
    print "Killing process %s" % pid
    os.system("kill %s" % pid)

  
