From db880111bde74c4a4a30e99d730ea665e437cead Mon Sep 17 00:00:00 2001 From: vuzlov Date: Mon, 21 Sep 2020 14:26:30 +0300 Subject: [PATCH] #16706 fix2. new command for ps command, dict (pid, name) output --- bin/killSalome.py | 19 ++++--------------- bin/killSalomeWithPort.py | 35 +++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bin/killSalome.py b/bin/killSalome.py index 36c241158..89431ecc3 100755 --- a/bin/killSalome.py +++ b/bin/killSalome.py @@ -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 diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index c28f64cf3..007e26f41 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -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 -- 2.39.2