OLD | NEW |
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) 2013, 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 subprocess | 15 import subprocess |
16 import sys | 16 import sys |
17 | 17 |
18 import utils | 18 import utils |
19 | 19 |
20 | 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', | |
31 'iexplore': 'iexplore.exe', | 30 'iexplore': 'iexplore.exe', |
32 'firefox': 'firefox.exe', | 31 'firefox': 'firefox.exe', |
33 'git': 'git.exe', | 32 'git': 'git.exe', |
34 'svn': 'svn.exe' | 33 'svn': 'svn.exe' |
35 }, | 34 }, |
36 'linux': { | 35 'linux': { |
37 'chrome': 'chrome', | 36 'chrome': 'chrome', |
38 'content_shell': 'content_shell', | 37 'content_shell': 'content_shell', |
39 'dart': 'dart', | 38 'dart': 'dart', |
40 'editor': 'DartEditor', | |
41 'java': 'java', | |
42 'eggplant': 'Eggplant', | |
43 'firefox': 'firefox.exe', | 39 'firefox': 'firefox.exe', |
44 'git': 'git', | 40 'git': 'git', |
45 'svn': 'svn' | 41 'svn': 'svn' |
46 }, | 42 }, |
47 'macos': { | 43 'macos': { |
48 'chrome': 'Chrome', | 44 'chrome': 'Chrome', |
49 'content_shell': 'Content Shell', | 45 'content_shell': 'Content Shell', |
50 'dart': 'dart', | 46 'dart': 'dart', |
51 'editor': 'DartEditor', | |
52 'firefox': 'firefox', | 47 'firefox': 'firefox', |
53 'safari': 'Safari', | 48 'safari': 'Safari', |
54 'git': 'git', | 49 'git': 'git', |
55 'svn': 'svn' | 50 'svn': 'svn' |
56 } | 51 } |
57 } | 52 } |
58 | 53 |
59 INFO_COMMAND = { | 54 INFO_COMMAND = { |
60 'win32': 'wmic process where Processid=%s get CommandLine', | 55 'win32': 'wmic process where Processid=%s get CommandLine', |
61 'macos': POSIX_INFO, | 56 'macos': POSIX_INFO, |
62 'linux': POSIX_INFO, | 57 'linux': POSIX_INFO, |
63 } | 58 } |
64 | 59 |
65 def GetOptions(): | 60 def GetOptions(): |
66 parser = optparse.OptionParser("usage: %prog [options]") | 61 parser = optparse.OptionParser("usage: %prog [options]") |
67 parser.add_option("--kill_dart", default=True, | 62 parser.add_option("--kill_dart", default=True, |
68 help="Kill all dart processes") | 63 help="Kill all dart processes") |
69 parser.add_option("--kill_vc", default=True, | 64 parser.add_option("--kill_vc", default=True, |
70 help="Kill all git and svn processes") | 65 help="Kill all git and svn processes") |
71 parser.add_option("--kill_browsers", default=False, | 66 parser.add_option("--kill_browsers", default=False, |
72 help="Kill all browser processes") | 67 help="Kill all browser processes") |
73 parser.add_option("--kill_editor", default=True, | |
74 help="Kill all editor processes") | |
75 (options, args) = parser.parse_args() | 68 (options, args) = parser.parse_args() |
76 return options | 69 return options |
77 | 70 |
78 | 71 |
79 def GetPidsPosix(process_name): | 72 def GetPidsPosix(process_name): |
80 # This is to have only one posix command, on linux we could just do: | 73 # This is to have only one posix command, on linux we could just do: |
81 # pidof process_name | 74 # pidof process_name |
82 cmd = 'ps -e -o pid= -o comm=' | 75 cmd = 'ps -e -o pid= -o comm=' |
83 # Sample output: | 76 # Sample output: |
84 # 1 /sbin/launchd | 77 # 1 /sbin/launchd |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 180 |
188 def KillVCSystems(): | 181 def KillVCSystems(): |
189 status = Kill('git') | 182 status = Kill('git') |
190 status += Kill('svn') | 183 status += Kill('svn') |
191 return status | 184 return status |
192 | 185 |
193 def KillDart(): | 186 def KillDart(): |
194 status = Kill("dart") | 187 status = Kill("dart") |
195 return status | 188 return status |
196 | 189 |
197 def KillEditor(): | |
198 status = Kill("editor") | |
199 if os_name == "linux": | |
200 # it is important to kill java after editor on linux | |
201 status += Kill("java") | |
202 status += Kill("eggplant") | |
203 return status | |
204 | |
205 def Main(): | 190 def Main(): |
206 options = GetOptions() | 191 options = GetOptions() |
207 status = 0 | 192 status = 0 |
208 if options.kill_dart: | 193 if options.kill_dart: |
209 status += KillDart() | 194 status += KillDart() |
210 if options.kill_vc: | 195 if options.kill_vc: |
211 status += KillVCSystems() | 196 status += KillVCSystems() |
212 if options.kill_browsers: | 197 if options.kill_browsers: |
213 status += KillBrowsers() | 198 status += KillBrowsers() |
214 if options.kill_editor: | |
215 status += KillEditor() | |
216 return status | 199 return status |
217 | 200 |
218 if __name__ == '__main__': | 201 if __name__ == '__main__': |
219 sys.exit(Main()) | 202 sys.exit(Main()) |
OLD | NEW |