Salome HOME
cda030b60752478c3b8bcc0e1bc28e1ac8ef37a7
[modules/kernel.git] / src / Logger / Test / TestKiller.py
1
2 import sys, os,signal,string,commands
3
4 def killNamingService():
5     """
6     kills omniORB4 Naming Service on local machine.
7     Selects process corresponding to the port used in $OMNIORB_CONFIG file.
8     Works only with a single line $OMNIORB_CONFIG like
9     InitRef = NameService=corbaname::<hostname>:<port>
10     """
11     fic=os.environ['OMNIORB_CONFIG']
12     f=open(fic,'r')
13     line=f.readline()
14     f.close()
15     port=string.split(line,':')[-1][0:4]
16     command='ps -eo pid,command | grep "omniNames -start '+str(port)+'"'
17     pid=string.split(commands.getoutput(command))[0]
18     os.kill(int(pid),signal.SIGKILL)
19
20
21 def killProcess(process_id):
22     """
23     kills process on local machine, given a dictionary of running process
24     generated by runSalome.Server() class and derived, (method run).
25     kills also local Naming server.
26     """
27     for pid, cmd in process_id.items():
28         print "stop process %s : %s"% (pid, cmd[0])
29         try:
30             os.kill(int(pid),signal.SIGKILL)
31         except:
32             print "  ---- process %s : %s inexistant"% (pid, cmd[0])
33             pass
34         del process_id[pid]
35         pass
36     killNamingService()