def WatchAndKill(pid, user=None, listOnly=False): print "WatchAndKill started with pid " + str(pid) procChk = {} procChk['^cmsRun '] = 60 * 60 * 3 procChk['/testing\.log;\s*fi\s*$'] = 60 * 30 procChk['python\s+whiteRabbit.py\s+'] = 60 * 60 * 2 procChk['/IB/runTests.py\s+'] = 60 * 60 * 8 procs = ProcessTree(user, detail=True, xinfo=None, show=False) startTime = -1 while True: procs.updateSelected(None, None, pid) if (len(procs.selectedTree) == 0) or (procs.all[pid].stime <= startTime): break startTime = procs.all[pid].stime for p in procs.selectedTree: proc = procs.all[p] maxRunAge = 0 for cmd in procChk: if re.search(cmd, proc.arg) and (proc.stime > procChk[cmd]): print "Job reached max allocated time: ", proc.arg, ' ===> ', proc.stime, '/', procChk[ cmd] proc2kill = ProcessTree(user, detail=True, xinfo=None, show=True) if listOnly: proc2kill.updateSelected(None, None, p) else: proc2kill.killSelected(None, None, p) time.sleep(60 * 10) procs.allProcesses(user) return