OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/kill.h" | 5 #include "base/process/kill.h" |
6 | 6 |
7 #include <io.h> | 7 #include <io.h> |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 if (result && wait) { | 94 if (result && wait) { |
95 // The process may not end immediately due to pending I/O | 95 // The process may not end immediately due to pending I/O |
96 if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000)) | 96 if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000)) |
97 DPLOG(ERROR) << "Error waiting for process exit"; | 97 DPLOG(ERROR) << "Error waiting for process exit"; |
98 } else if (!result) { | 98 } else if (!result) { |
99 DPLOG(ERROR) << "Unable to terminate process"; | 99 DPLOG(ERROR) << "Unable to terminate process"; |
100 } | 100 } |
101 return result; | 101 return result; |
102 } | 102 } |
103 | 103 |
104 // Attempts to kill the process identified by the given process | |
105 // entry structure, giving it the specified exit code. | |
106 // Returns true if this is successful, false otherwise. | |
107 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { | |
108 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, | |
109 FALSE, // Don't inherit handle | |
110 process_id); | |
111 if (!process) { | |
112 DPLOG(ERROR) << "Unable to open process " << process_id; | |
113 return false; | |
114 } | |
115 bool ret = KillProcess(process, exit_code, wait); | |
116 CloseHandle(process); | |
117 return ret; | |
118 } | |
119 | |
120 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) { | 104 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) { |
121 DWORD tmp_exit_code = 0; | 105 DWORD tmp_exit_code = 0; |
122 | 106 |
123 if (!::GetExitCodeProcess(handle, &tmp_exit_code)) { | 107 if (!::GetExitCodeProcess(handle, &tmp_exit_code)) { |
124 DPLOG(FATAL) << "GetExitCodeProcess() failed"; | 108 DPLOG(FATAL) << "GetExitCodeProcess() failed"; |
125 if (exit_code) { | 109 if (exit_code) { |
126 // This really is a random number. We haven't received any | 110 // This really is a random number. We haven't received any |
127 // information about the exit code, presumably because this | 111 // information about the exit code, presumably because this |
128 // process doesn't have permission to get the exit code, or | 112 // process doesn't have permission to get the exit code, or |
129 // because of some other cause for GetExitCodeProcess to fail | 113 // because of some other cause for GetExitCodeProcess to fail |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 201 } |
218 | 202 |
219 MessageLoop::current()->PostDelayedTask( | 203 MessageLoop::current()->PostDelayedTask( |
220 FROM_HERE, | 204 FROM_HERE, |
221 Bind(&TimerExpiredTask::TimedOut, | 205 Bind(&TimerExpiredTask::TimedOut, |
222 Owned(new TimerExpiredTask(process.Pass()))), | 206 Owned(new TimerExpiredTask(process.Pass()))), |
223 TimeDelta::FromMilliseconds(kWaitInterval)); | 207 TimeDelta::FromMilliseconds(kWaitInterval)); |
224 } | 208 } |
225 | 209 |
226 } // namespace base | 210 } // namespace base |
OLD | NEW |