Salome HOME
PAL6948 (Persistence in MED). Add "typedef H5T_order_t hdf_byte_order;"
[modules/kernel.git] / bin / killSalomeWithPort.py
1 #!/usr/bin/env python
2 import os, sys, pickle, signal, commands
3
4 def getPiDict(port,appname='salome',full=True):
5     filedict = []
6     filedict.append( os.getenv('USER') )          # user name
7     filedict.append( os.getenv('HOSTNAME') )      # host name
8     filedict.append( str(port) )                  # port number
9     filedict.append( appname.upper() )            # application name
10     filedict.append( 'pidict' )                   # constant part
11
12     filedict = '_'.join(filedict)
13     if full:
14         filedict = os.getenv("HOME") + '/' + filedict
15     return filedict
16
17 ########## kills all salome processes with the given port ##########
18 def killMyPort(port):
19     filedict=getPiDict(port)
20     found = 0
21     try:
22         fpid=open(filedict, 'r')
23         found = 1
24     except:
25         print "le fichier %s des process SALOME n'est pas accessible"% filedict
26         pass
27         
28     if found:
29         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 >& /dev/null")
30         try:
31             process_ids=pickle.load(fpid)
32             fpid.close()
33             for process_id in process_ids:
34
35                 for pid, cmd in process_id.items():
36                     print "stop process %s : %s"% (pid, cmd[0])
37                     try:
38                         os.kill(int(pid),signal.SIGKILL)
39                     except:
40                         print "  ------------------ process %s : %s inexistant"% (pid, cmd[0])
41                         pass
42                 pass
43         except:
44             pass
45         os.remove(filedict)
46         pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
47         a = ""
48         while pid != "" and len(a.split(" ")) < 2:
49             a = commands.getoutput("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid")
50             pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
51             print pid
52               
53
54 if __name__ == "__main__":
55     for port in sys.argv[1:]:
56         killMyPort(port)