CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Validation/Performance/scripts/cmsPerfSuiteKill.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #Utility script to kill with one command any cmsPerfSuite.py related process running.
00003 ######NOTE######
00004 #USE AT YOUR OWN RISK!
00005 #THIS SCRIPT WILL KILL ANY PROCESS THE USER HAS RUNNING THAT COULD BE PART OF
00006 #THE PERFORMANCE SUITE EXECUTION!
00007 import subprocess,os,sys,cmsScimarkStop,time
00008 user=os.environ['USER']
00009 
00010 def main():
00011     exitcode=0
00012     #First invoke cmsScimarkStop.py to stop eventual cmsScimarks running...
00013     cmsScimarkStop.main()
00014     
00015     #List of executables to spot in ps -ef and kill:
00016     scripts=['cmsPerfSuite.py',
00017              'cmsRelvalreportInput.py',
00018              'cmsRelvalreport.py',
00019              'cmsDriver.py',
00020              'cmsRun',
00021              'cmsScimark2',
00022              'cmsIgProf_Analysis.py',
00023              'igprof-analyse',
00024              'perfreport'
00025              ]
00026          
00027     
00028     print "Looking for processes by user %s"%user
00029     checkProcesses=subprocess.Popen("ps -efww|grep %s"%user,bufsize=4096,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
00030     for line in checkProcesses.stdout:
00031         for executable in scripts:
00032             #print "Looking for %s script"%executable
00033             if executable in line:
00034                 print "Found process %s"%line
00035                 print "Killing it!"
00036                 PID=line.split()[1]
00037                 kill_stdouterr=subprocess.Popen("kill %s"%PID,shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read()
00038                 print kill_stdouterr
00039                 
00040     #There could be a few more processes spawned after some of the killings... give it a couple of iterations:
00041     i=0
00042     while i<100:
00043         exitcode=0
00044         checkProcesses=subprocess.Popen("ps -efww|grep %s"%user,bufsize=4096,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
00045         for line in checkProcesses.stdout:
00046             for executable in scripts:
00047                 if executable in line:
00048                     print "Something funny going on! It seems I could not kill process:\n%s"%line
00049                     print "SORRY!"
00050                     exitcode=-1
00051         if exitcode>=0:
00052             print "Finally killed all jobs!"
00053             break
00054         i+=1
00055         time.sleep(2)
00056     #Return 0 if all killed, could use the -1 exit code if we decide to put a limit to the number of cycles...
00057     return exitcode
00058 
00059 if __name__ == "__main__":
00060     sys.exit(main())