Back to index

salome-kernel  6.5.0
TestKiller.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 import sys, os,signal,string,commands
00025 
00026 def killNamingService():
00027     """
00028     kills omniORB4 Naming Service on local machine.
00029     Selects process corresponding to the port used in $OMNIORB_CONFIG file.
00030     Works only with a single line $OMNIORB_CONFIG like
00031     InitRef = NameService=corbaname::<hostname>:<port>
00032     """
00033     fic=os.environ['OMNIORB_CONFIG']
00034     f=open(fic,'r')
00035     line=f.readline()
00036     f.close()
00037     port=string.split(line,':')[-1][0:4]
00038     command='ps -eo pid,command | grep "omniNames -start '+str(port)+'"'
00039     pid=string.split(commands.getoutput(command))[0]
00040     os.kill(int(pid),signal.SIGKILL)
00041 
00042 
00043 def killProcess(process_id):
00044     """
00045     kills process on local machine, given a dictionary of running process
00046     generated by runSalome.Server() class and derived, (method run).
00047     kills also local Naming server.
00048     """
00049     for pid, cmd in process_id.items():
00050         print "stop process %s : %s"% (pid, cmd[0])
00051         try:
00052             os.kill(int(pid),signal.SIGKILL)
00053         except:
00054             print "  ---- process %s : %s inexistant"% (pid, cmd[0])
00055             pass
00056         del process_id[pid]
00057         pass
00058     killNamingService()