Salome HOME
PAL13340 : fix launching problem on 64-bit platforms (more correct check)
[modules/kernel.git] / bin / addToKillList.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
4 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either 
8 # version 2.1 of the License.
9
10 # This library is distributed in the hope that it will be useful 
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public  
16 # License along with this library; if not, write to the Free Software 
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20
21
22 import os, sys, pickle, string, signal
23
24 ########## adds to the kill list of SALOME one more process ##########
25
26 def findFileDict():
27     if os.environ.has_key('NSPORT'):
28         my_port = os.environ['NSPORT']
29         pass
30     else:
31         my_port = 2809
32         try:
33             file = open(os.environ["OMNIORB_CONFIG"], "r")
34             s = file.read()
35             while len(s):
36                 l = string.split(s, ":")
37                 if string.split(l[0], " ")[0] == "ORBInitRef" or string.split(l[0], " ")[0] == "InitRef" :
38                     my_port = int(l[len(l)-1])
39                     pass
40                 s = file.read()
41                 pass
42             pass
43         except:
44             pass
45         pass
46     print "myport = ", my_port
47     return my_port
48     
49 def addToKillList(command_pid, command):
50     my_port = findFileDict()
51     from killSalomeWithPort import getPiDict
52     filedict=getPiDict(my_port)
53     try:
54         fpid=open(filedict, 'r')
55         process_ids=pickle.load(fpid)
56         fpid.close()
57     except:
58         process_ids=[{}]
59         pass
60         
61     already_in=0
62     for process_id in process_ids:
63         print process_id
64         for pid, cmd in process_id.items():
65             #print "see process %s : %s"% (pid, cmd[0])
66             if pid == command_pid:
67                 already_in=1
68                 pass
69             pass
70         pass
71
72     command=(command.split(" "))[0]
73     if already_in == 0:
74         try:
75             process_ids.append({command_pid: [command]})
76             fpid=open(filedict,'w')
77             pickle.dump(process_ids, fpid)
78             fpid.close()
79         except:
80             print "addToKillList: can not add command %s to the kill list"% filedict
81             pass
82         pass
83     pass
84
85 def killList():
86     my_port = findFileDict()
87     from killSalomeWithPort import getPiDict
88     filedict=getPiDict(my_port)
89     try:
90         fpid=open(filedict, 'r')
91         process_ids=pickle.load(fpid)
92         fpid.close()
93     except:
94         process_ids=[{}]
95         pass
96
97     for process_id in process_ids:
98         print process_id
99         for pid, cmd in process_id.items():
100             print "stop process %s : %s"% (pid, cmd[0])
101             try:
102                 os.kill(int(pid),signal.SIGKILL)
103             except:
104                 print "  ------------------ process %s : %s inexistant"% (pid, cmd[0])
105                 pass
106             pass
107         pass
108     os.remove(filedict)
109     pass
110   
111
112
113 if __name__ == "__main__":
114     print sys.argv
115     addToKillList(sys.argv[1], sys.argv[2])