History

add hg and python

cinap_lenrek committed 15 years ago

Commit 4bb9e221 parent 987265c3706 files · +1228772 −-233Browse files

Showing the changes to sys/src/cmd/python/Tools/buildbot/kill_python.c (1 of 3706 files). Show all

Unified · Split

sys/src/cmd/python/Tools/buildbot/kill_python.c+68−0
@@ -0,0 +1,68 @@
1+/* This program looks for processes which have build\PCbuild\python.exe
2+ in their path and terminates them. */
3+#include <windows.h>
4+#include <psapi.h>
5+#include <stdio.h>
6+
7+int main()
8+{
9+ DWORD pids[1024], cbNeeded;
10+ int i, num_processes;
11+ if (!EnumProcesses(pids, sizeof(pids), &cbNeeded)) {
12+ printf("EnumProcesses failed\n");
13+ return 1;
14+ }
15+ num_processes = cbNeeded/sizeof(pids[0]);
16+ for (i = 0; i < num_processes; i++) {
17+ HANDLE hProcess;
18+ char path[MAX_PATH];
19+ HMODULE mods[1024];
20+ int k, num_mods;
21+ hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
22+ | PROCESS_VM_READ
23+ | PROCESS_TERMINATE ,
24+ FALSE, pids[i]);
25+ if (!hProcess)
26+ /* process not accessible */
27+ continue;
28+ if (!EnumProcessModules(hProcess, mods, sizeof(mods), &cbNeeded)) {
29+ /* For unknown reasons, this sometimes returns ERROR_PARTIAL_COPY;
30+ this apparently means we are not supposed to read the process. */
31+ if (GetLastError() == ERROR_PARTIAL_COPY) {
32+ CloseHandle(hProcess);
33+ continue;
34+ }
35+ printf("EnumProcessModules failed: %d\n", GetLastError());
36+ return 1;
37+ }
38+ if (!GetModuleFileNameEx(hProcess, NULL, path, sizeof(path))) {
39+ printf("GetProcessImageFileName failed\n");
40+ return 1;
41+ }
42+
43+ _strlwr(path);
44+ /* printf("%s\n", path); */
45+
46+ /* Check if we are running a buildbot version of Python.
47+
48+ On Windows, this will always be a debug build from the
49+ PCbuild directory. build\\PCbuild\\python_d.exe
50+
51+ On Cygwin, the pathname is similar to other Unixes.
52+ Use \\build\\python.exe to ensure we don't match
53+ PCbuild\\python.exe which could be a normal instance
54+ of Python running on vanilla Windows.
55+ */
56+ if ((strstr(path, "build\\pcbuild\\python_d.exe") != NULL) ||
57+ (strstr(path, "\\build\\python.exe") != NULL)) {
58+ printf("Terminating %s (pid %d)\n", path, pids[i]);
59+ if (!TerminateProcess(hProcess, 1)) {
60+ printf("Termination failed: %d\n", GetLastError());
61+ return 1;
62+ }
63+ return 0;
64+ }
65+
66+ CloseHandle(hProcess);
67+ }
68+}