]> SALOME platform Git repositories - modules/kernel.git/blob - bin/killSalome.py
Salome HOME
Another fix of hack_libtool() function for latest versions of autoconf (e.g. 2.67)
[modules/kernel.git] / bin / killSalome.py
1 #! /usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 #  This library is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU Lesser General Public
10 #  License as published by the Free Software Foundation; either
11 #  version 2.1 of the License.
12 #
13 #  This library is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  Lesser General Public License for more details.
17 #
18 #  You should have received a copy of the GNU Lesser General Public
19 #  License along with this library; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24
25 ## \file killSalome.py
26 #  Stop all %SALOME servers from all sessions by killing them
27 #
28
29 import os, sys, re, signal
30
31 from killSalomeWithPort import killMyPort, getPiDict
32
33 def killAllPorts():
34     """
35     Kill all SALOME sessions belonging to the user.
36     """
37     user = os.getenv('USER')
38     # new-style dot-prefixed pidict file
39     #fpidict   = getPiDict('(\d*)',hidden=True)
40     #problem with WIN32 path slashes
41     fpidict   = getPiDict('#####',hidden=True)
42     dirpidict = os.path.dirname(fpidict)
43     fpidict   = os.path.basename(fpidict)
44     fpidict = fpidict.replace('#####', '(\d*)')
45     fnamere   = re.compile("^%s$" % fpidict)
46     try:
47         for f in os.listdir(dirpidict):
48             mo = fnamere.match(f)
49             try:
50                 killMyPort(mo.group(1))
51             except:
52                 pass
53             pass
54         pass
55     except:
56         pass
57     # provide compatibility with old-style pidict file (not dot-prefixed)
58     #fpidict   = getPiDict('(\d*)',hidden=False)
59     fpidict   = getPiDict('#####',hidden=True)
60     dirpidict = os.path.dirname(fpidict)
61     fpidict   = os.path.basename(fpidict)
62     fpidict = fpidict.replace('#####', '(\d*)')
63     fnamere   = re.compile("^%s$" % fpidict)
64     try:
65         for f in os.listdir(dirpidict):
66             mo = fnamere.match(f)
67             try:
68                 killMyPort(mo.group(1))
69             except:
70                 pass
71             pass
72         pass
73     except:
74         pass
75     # kill other processes
76     if sys.platform != 'win32':
77         import commands
78         cmd = "ps -fea | grep '%s' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'" % user
79         prc = commands.getoutput(cmd)
80         for field in prc.split():
81             try:
82                 os.kill(int(field), signal.SIGKILL)
83             except:
84                 pass
85             pass
86         pass
87     pass
88
89 if __name__ == "__main__":
90     killAllPorts()
91     pass
92