2 import os, sys, pickle, signal, commands
4 def getPiDict(port,appname='salome',full=True):
5 from Utils_Identity import getShortHostName
7 host = os.getenv("HOSTNAME")
9 host = os.getenv("HOST")
11 host = getShortHostName()
14 filedict.append( os.getenv('USER') ) # user name
15 filedict.append( host ) # host name
16 filedict.append( str(port) ) # port number
17 filedict.append( appname.upper() ) # application name
18 filedict.append( 'pidict' ) # constant part
20 filedict = '_'.join(filedict)
22 filedict = os.getenv("HOME") + '/' + filedict
25 ########## kills all salome processes with the given port ##########
27 filedict=getPiDict(port)
30 fpid=open(filedict, 'r')
33 print "le fichier %s des process SALOME n'est pas accessible"% filedict
37 cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'"` ; echo $pid > /tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log'
40 fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log')
41 prc = fpidomniNames.read()
44 for field in prc.split(" ") :
45 if field == "omniNames" :
46 if pidfield != "egrep" :
47 print 'stop process '+pidfield+' : omniNames'
48 os.system('kill -9 '+pidfield)
53 process_ids=pickle.load(fpid)
55 for process_id in process_ids:
57 for pid, cmd in process_id.items():
58 print "stop process %s : %s"% (pid, cmd[0])
60 os.kill(int(pid),signal.SIGKILL)
62 print " ------------------ process %s : %s inexistant"% (pid, cmd[0])
68 pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
70 while pid != "" and len(a.split(" ")) < 2:
71 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")
72 pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
76 if __name__ == "__main__":
77 for port in sys.argv[1:]: