Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: tools/task_kill.py

Issue 350483003: Build Tools Cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: more fixes as reviewed by ricow Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/revert.py ('k') | tools/test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 # 6 #
7 7
8 # A script to kill hanging processs. The tool will return non-zero if any 8 # A script to kill hanging processs. The tool will return non-zero if any
9 # process was actually found. 9 # process was actually found.
10 # 10 #
11 11
12 import optparse 12 import optparse
13 import os 13 import os
14 import signal 14 import signal
15 import shutil
16 import string
17 import subprocess 15 import subprocess
18 import sys 16 import sys
17
19 import utils 18 import utils
20 19
20
21 os_name = utils.GuessOS() 21 os_name = utils.GuessOS()
22 22
23 POSIX_INFO = 'ps -p %s -o args' 23 POSIX_INFO = 'ps -p %s -o args'
24 24
25 EXECUTABLE_NAMES = { 25 EXECUTABLE_NAMES = {
26 'win32': { 26 'win32': {
27 'chrome': 'chrome.exe', 27 'chrome': 'chrome.exe',
28 'content_shell': 'content_shell.exe', 28 'content_shell': 'content_shell.exe',
29 'dart': 'dart.exe', 29 'dart': 'dart.exe',
30 'editor': 'DartEditor.exe', 30 'editor': 'DartEditor.exe',
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 results = [] 111 results = []
112 lines = output.splitlines() 112 lines = output.splitlines()
113 113
114 for line in lines: 114 for line in lines:
115 split = line.split() 115 split = line.split()
116 if len(split) > 2 and split[0] == process_name: 116 if len(split) > 2 and split[0] == process_name:
117 results.append(split[1]) 117 results.append(split[1])
118 return results 118 return results
119 119
120 def GetPids(process_name): 120 def GetPids(process_name):
121 if (os_name == "win32"): 121 if os_name == "win32":
122 return GetPidsWindows(process_name) 122 return GetPidsWindows(process_name)
123 else: 123 else:
124 return GetPidsPosix(process_name) 124 return GetPidsPosix(process_name)
125 125
126 def PrintPidInfo(pid): 126 def PrintPidInfo(pid):
127 # We asume that the list command will return lines in the format: 127 # We assume that the list command will return lines in the format:
128 # EXECUTABLE_PATH ARGS 128 # EXECUTABLE_PATH ARGS
129 # There may be blank strings in the output 129 # There may be blank strings in the output
130 p = subprocess.Popen(INFO_COMMAND[os_name] % pid, 130 p = subprocess.Popen(INFO_COMMAND[os_name] % pid,
131 stdout=subprocess.PIPE, 131 stdout=subprocess.PIPE,
132 stderr=subprocess.PIPE, 132 stderr=subprocess.PIPE,
133 shell=True) 133 shell=True)
134 output, stderr = p.communicate() 134 output, stderr = p.communicate()
135 lines = output.splitlines() 135 lines = output.splitlines()
136 136
137 # Pop the header 137 # Pop the header
138 lines.pop(0) 138 lines.pop(0)
139 for line in lines: 139 for line in lines:
140 # wmic will output a bunch of empty strings, we ignore these 140 # wmic will output a bunch of empty strings, we ignore these
141 if len(line) >= 1: 141 if len(line) >= 1:
142 print("Hanging process info:") 142 print("Hanging process info:")
143 print(" PID: %s" % pid) 143 print(" PID: %s" % pid)
144 print(" Command line: %s" % line) 144 print(" Command line: %s" % line)
145 145
146 146
147 def KillPosix(pid): 147 def KillPosix(pid):
148 try: 148 try:
149 os.kill(int(pid), signal.SIGKILL); 149 os.kill(int(pid), signal.SIGKILL)
150 except: 150 except:
151 # Ignore this, the process is already dead from killing another process. 151 # Ignore this, the process is already dead from killing another process.
152 pass 152 pass
153 153
154 def KillWindows(pid): 154 def KillWindows(pid):
155 # os.kill is not available until python 2.7 155 # os.kill is not available until python 2.7
156 cmd = "taskkill /F /PID %s" % pid 156 cmd = "taskkill /F /PID %s" % pid
157 p = subprocess.Popen(cmd, 157 p = subprocess.Popen(cmd,
158 stdout=subprocess.PIPE, 158 stdout=subprocess.PIPE,
159 stderr=subprocess.PIPE, 159 stderr=subprocess.PIPE,
160 shell=True) 160 shell=True)
161 p.communicate() 161 p.communicate()
162 162
163 def Kill(name): 163 def Kill(name):
164 if (name not in EXECUTABLE_NAMES[os_name]): 164 if name not in EXECUTABLE_NAMES[os_name]:
165 return 0 165 return 0
166 print("***************** Killing %s *****************" % name) 166 print("***************** Killing %s *****************" % name)
167 platform_name = EXECUTABLE_NAMES[os_name][name] 167 platform_name = EXECUTABLE_NAMES[os_name][name]
168 pids = GetPids(platform_name) 168 pids = GetPids(platform_name)
169 for pid in pids: 169 for pid in pids:
170 PrintPidInfo(pid); 170 PrintPidInfo(pid)
171 if (os_name == "win32"): 171 if os_name == "win32":
172 KillWindows(pid) 172 KillWindows(pid)
173 else: 173 else:
174 KillPosix(pid) 174 KillPosix(pid)
175 print("Killed pid: %s" % pid) 175 print("Killed pid: %s" % pid)
176 if (len(pids) == 0): 176 if len(pids) == 0:
177 print(" No %s processes found." % name) 177 print(" No %s processes found." % name)
178 return len(pids) 178 return len(pids)
179 179
180 def KillBrowsers(): 180 def KillBrowsers():
181 status = Kill('firefox') 181 status = Kill('firefox')
182 status += Kill('chrome') 182 status += Kill('chrome')
183 status += Kill('iexplore') 183 status += Kill('iexplore')
184 status += Kill('safari') 184 status += Kill('safari')
185 status += Kill('content_shell') 185 status += Kill('content_shell')
186 return status 186 return status
(...skipping 11 matching lines...) Expand all
198 status = Kill("editor") 198 status = Kill("editor")
199 if os_name == "linux": 199 if os_name == "linux":
200 # it is important to kill java after editor on linux 200 # it is important to kill java after editor on linux
201 status += Kill("java") 201 status += Kill("java")
202 status += Kill("eggplant") 202 status += Kill("eggplant")
203 return status 203 return status
204 204
205 def Main(): 205 def Main():
206 options = GetOptions() 206 options = GetOptions()
207 status = 0 207 status = 0
208 if (options.kill_dart): 208 if options.kill_dart:
209 status += KillDart(); 209 status += KillDart()
210 if (options.kill_vc): 210 if options.kill_vc:
211 status += KillVCSystems(); 211 status += KillVCSystems()
212 if (options.kill_browsers): 212 if options.kill_browsers:
213 status += KillBrowsers() 213 status += KillBrowsers()
214 if (options.kill_editor): 214 if options.kill_editor:
215 status += KillEditor() 215 status += KillEditor()
216 return status 216 return status
217 217
218 if __name__ == '__main__': 218 if __name__ == '__main__':
219 sys.exit(Main()) 219 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/revert.py ('k') | tools/test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698