]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
#16706 fix2. new command for ps command, dict (pid, name) output
authorvuzlov <vuzlov@opencascade.com>
Mon, 21 Sep 2020 11:26:30 +0000 (14:26 +0300)
committervuzlov <vuzlov@opencascade.com>
Mon, 21 Sep 2020 11:26:30 +0000 (14:26 +0300)
bin/killSalome.py
bin/killSalomeWithPort.py

index 36c2411584d23682bee1ebe7bf6ffa08f291cb4f..89431ecc3c0266346a49494b2ee44f03c06d1443 100755 (executable)
@@ -28,7 +28,7 @@
 
 import os, sys, re, signal
 
-from killSalomeWithPort import killMyPort, getPiDict
+from killSalomeWithPort import killMyPort, getPiDict, checkUnkilledProcess
 #from salome_utils import getHostName, getShortHostName
 from salome_utils import getUserName
 
@@ -83,21 +83,10 @@ def killAllPorts():
     # kill other processes
     if sys.platform != 'win32':
         import subprocess
-        cmd = "ps -fea | grep '%s' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'" % user
-        prc = subprocess.getoutput(cmd)
-        for field in prc.split():
+        prc = checkUnkilledProcess()
+        for field in prc.keys():
             try:
-                os.kill(int(field), signal.SIGKILL)
-            except:
-                pass
-            pass
-        pass
-        # kill ompi-server needed for MPI containers coupling
-        cmd = "ps -fea | grep '%s' | grep 'ompi-server' | grep -v 'grep' | awk '{print $2}'" % user
-        prc = subprocess.getoutput(cmd)
-        for field in prc.split():
-            try:
-                os.kill(int(field), signal.SIGKILL)
+                os.kill(field, signal.SIGKILL)
             except:
                 pass
             pass
index c28f64cf3df1397d2b737fd5e79a409245ba2553..007e26f41b0a0f517f437e605179908c41798606 100755 (executable)
@@ -243,7 +243,7 @@ def __killMyPort(port, filedict):
                         killpid(int(pid))
                     except:
                         if verbose(): print("  ------------------ process %s : %s not found"% (pid, cmd[0]))
-                        if int(pid) in checkUnkillProcess():
+                        if int(pid) in checkUnkilledProcess().keys():
                             try:
                                 killpid(int(pid))
                             except:
@@ -399,32 +399,39 @@ def killMyPortSpy(pid, port):
     killMyPort(port)
     return
 
-def checkUnkillProcess():
+def checkUnkilledProcess():
     #check process in system after kill
     from salome_utils import getUserName
     user = getUserName()
     if sys.platform != 'win32':
         import subprocess
-        cmd = "ps -fea | grep '%s' | grep -e 'SALOME_' -e 'omniNames' | awk '{print $2}'" % user
+        cmd = 'ps --noheading -U "%s" -o pid,cmd | awk \'{printf("%s %s\\n", $1, $2)}\'' % (user, "%s", "%s")
         prc = subprocess.getoutput(cmd)
-        if prc:
-            print("Salome process aren't killed\nCheck this PID: ", prc)
-            pass
+        prc = prc.split()
+        prc = dict(zip(list(map(int, prc[::2])), prc[1::2]))
+        prc = dict(filter(lambda elem: any(subs in elem[1] for subs in ['SALOME_', 'omniNames']), prc.items()))
+        print(prc)
+        cmd = 'ps -fea | grep \'%s\' | grep \'ghs3d\' | grep \'f /tmp/GHS3D_\' | grep -v \'grep\' | awk \'{print("%s %s\\n", $2, $8)}\'' % (user, "%s", "%s")
+        ghs = subprocess.getoutput(cmd)
+        ghs = ghs.split()
+        ghs = dict(zip(list(map(int, ghs[::2])), ghs[1::2]))
+        prc.update(ghs)
+        cmd = 'ps -fea | grep \'%s\' | grep \'ompi-server\' | grep -v \'grep\' | awk \'{print("%s %s\\n", $2, $8)}\'' % (user, "%s", "%s")
+        ompi = subprocess.getoutput(cmd)
+        ompi = ompi.split()
+        ompi = dict(zip(list(map(int, ompi[::2])), ompi[1::2]))
+        prc.update(ompi)
         return prc
     else:
         import subprocess
         cmd = 'tasklist /fo csv | findstr /i "SALOME_ omniNames"'
         prc = subprocess.getoutput(cmd)
-        # get only PID
         try:
             prc = prc.split()
             prc = [prc[i].split(',') for i in range(0, len(prc)) if i % 2 == 0]
-            prc = [int(prc[j][1].replace('"', '')) for j in range(0, len(prc))]
+            prc = dict([(int(prc[j][1].replace('"', '')), prc[j][0].replace('"', '')) for j in range(0, len(prc))])
         except:
             pass
-        if prc:
-            print("Salome process aren't killed\nCheck this PID: ", prc)
-            pass
         return prc
 
 if __name__ == "__main__":
@@ -444,7 +451,11 @@ if __name__ == "__main__":
         sys.exit(0)
         pass
     elif sys.argv[1] == "--find":
-        checkUnkillProcess()
+        pidcmd = checkUnkilledProcess()
+        if pidcmd:
+            print("Unkilled processes: ")
+            print()
+            print(pidcmd)
         sys.exit(0)
     try:
         from salomeContextUtils import setOmniOrbUserPath #@UnresolvedImport