Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/kernel.git] / bin / killSalomeWithPort.py
1 #!/usr/bin/env python
2 import os, sys, pickle, signal, commands
3
4 ########## kills all salome processes with the given port ##########
5 def killMyPort(port):
6     filedict='/tmp/'+os.getenv('USER')+"_"+port+'_SALOME_pidict'
7     found = 0
8     try:
9         fpid=open(filedict, 'r')
10         found = 1
11     except:
12         print "le fichier %s des process SALOME n'est pas accessible"% filedict
13         pass
14         
15     if found:
16         a = os.system("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid")
17         try:
18             process_ids=pickle.load(fpid)
19             fpid.close()
20             for process_id in process_ids:
21
22                 for pid, cmd in process_id.items():
23                     print "stop process %s : %s"% (pid, cmd[0])
24                     try:
25                         os.kill(int(pid),signal.SIGKILL)
26                     except:
27                         print "  ------------------ process %s : %s inexistant"% (pid, cmd[0])
28                         pass
29                 pass
30         except:
31             pass
32         os.remove(filedict)
33         pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
34         while pid != "":
35             a = os.system("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid")
36             pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
37               
38
39 if __name__ == "__main__":
40     for port in sys.argv[1:]:
41         killMyPort(port)