CMS 3D CMS Logo

cmsPerfSuiteKill.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #Utility script to kill with one command any cmsPerfSuite.py related process running.
3 ######NOTE######
4 #USE AT YOUR OWN RISK!
5 #THIS SCRIPT WILL KILL ANY PROCESS THE USER HAS RUNNING THAT COULD BE PART OF
6 #THE PERFORMANCE SUITE EXECUTION!
7 from __future__ import print_function
8 import subprocess,os,sys,cmsScimarkStop,time
9 user=os.environ['USER']
10 
11 def main():
12  exitcode=0
13  #First invoke cmsScimarkStop.py to stop eventual cmsScimarks running...
15 
16  #List of executables to spot in ps -ef and kill:
17  scripts=['cmsPerfSuite.py',
18  'cmsRelvalreportInput.py',
19  'cmsRelvalreport.py',
20  'cmsDriver.py',
21  'cmsRun',
22  'cmsScimark2',
23  'cmsIgProf_Analysis.py',
24  'igprof-analyse',
25  'perfreport'
26  ]
27 
28 
29  print("Looking for processes by user %s"%user)
30  checkProcesses=subprocess.Popen("ps -efww|grep %s"%user,bufsize=4096,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
31  for line in checkProcesses.stdout:
32  for executable in scripts:
33  #print "Looking for %s script"%executable
34  if executable in line:
35  print("Found process %s"%line)
36  print("Killing it!")
37  PID=line.split()[1]
38  kill_stdouterr=subprocess.Popen("kill %s"%PID,shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read()
39  print(kill_stdouterr)
40 
41  #There could be a few more processes spawned after some of the killings... give it a couple of iterations:
42  i=0
43  while i<100:
44  exitcode=0
45  checkProcesses=subprocess.Popen("ps -efww|grep %s"%user,bufsize=4096,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
46  for line in checkProcesses.stdout:
47  for executable in scripts:
48  if executable in line:
49  print("Something funny going on! It seems I could not kill process:\n%s"%line)
50  print("SORRY!")
51  exitcode=-1
52  if exitcode>=0:
53  print("Finally killed all jobs!")
54  break
55  i+=1
56  time.sleep(2)
57  #Return 0 if all killed, could use the -1 exit code if we decide to put a limit to the number of cycles...
58  return exitcode
59 
60 if __name__ == "__main__":
61  sys.exit(main())
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
Definition: main.py:1