Salome HOME
PAL6948 (Persistence in MED). Add "typedef H5T_order_t hdf_byte_order;"
[modules/kernel.git] / bin / killSalomeWithPort.py
index 7c8dcd2ed1800c80f269142caef2488c702616c4..7cc60a73dfd84f9e972afd36abfd4554cdde6b66 100755 (executable)
@@ -1,9 +1,22 @@
 #!/usr/bin/env python
 import os, sys, pickle, signal, commands
 
+def getPiDict(port,appname='salome',full=True):
+    filedict = []
+    filedict.append( os.getenv('USER') )          # user name
+    filedict.append( os.getenv('HOSTNAME') )      # host name
+    filedict.append( str(port) )                  # port number
+    filedict.append( appname.upper() )            # application name
+    filedict.append( 'pidict' )                   # constant part
+
+    filedict = '_'.join(filedict)
+    if full:
+        filedict = os.getenv("HOME") + '/' + filedict
+    return filedict
+
 ########## kills all salome processes with the given port ##########
 def killMyPort(port):
-    filedict='/tmp/'+os.getenv('USER')+"_"+port+'_SALOME_pidict'
+    filedict=getPiDict(port)
     found = 0
     try:
         fpid=open(filedict, 'r')
@@ -13,7 +26,7 @@ def killMyPort(port):
         pass
         
     if found:
-        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")
+        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")
         try:
             process_ids=pickle.load(fpid)
             fpid.close()
@@ -31,9 +44,11 @@ def killMyPort(port):
             pass
         os.remove(filedict)
         pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
-        while pid != "":
-            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")
+       a = ""
+        while pid != "" and len(a.split(" ")) < 2:
+            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")
             pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
+           print pid
               
 
 if __name__ == "__main__":