| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <dirent.h> | 5 #include <dirent.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 | 47 |
| 48 int GetProcId(ProcessHandle process) { | 48 int GetProcId(ProcessHandle process) { |
| 49 return process; | 49 return process; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Attempts to kill the process identified by the given process | 52 // Attempts to kill the process identified by the given process |
| 53 // entry structure. Ignores specified exit_code; posix can't force that. | 53 // entry structure. Ignores specified exit_code; posix can't force that. |
| 54 // Returns true if this is successful, false otherwise. | 54 // Returns true if this is successful, false otherwise. |
| 55 bool KillProcess(int process_id, int exit_code, bool wait) { | 55 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { |
| 56 bool result = false; | 56 bool result = false; |
| 57 | 57 |
| 58 int status = kill(process_id, SIGTERM); | 58 int status = kill(process_id, SIGTERM); |
| 59 if (!status && wait) { | 59 if (!status && wait) { |
| 60 int tries = 60; | 60 int tries = 60; |
| 61 // The process may not end immediately due to pending I/O | 61 // The process may not end immediately due to pending I/O |
| 62 while (tries-- > 0) { | 62 while (tries-- > 0) { |
| 63 int pid = waitpid(process_id, &status, WNOHANG); | 63 int pid = waitpid(process_id, &status, WNOHANG); |
| 64 if (pid == process_id) { | 64 if (pid == process_id) { |
| 65 result = true; | 65 result = true; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 const ProcessFilter* filter) { | 332 const ProcessFilter* filter) { |
| 333 bool exited_cleanly = | 333 bool exited_cleanly = |
| 334 WaitForProcessesToExit(executable_name, wait_milliseconds, | 334 WaitForProcessesToExit(executable_name, wait_milliseconds, |
| 335 filter); | 335 filter); |
| 336 if (!exited_cleanly) | 336 if (!exited_cleanly) |
| 337 KillProcesses(executable_name, exit_code, filter); | 337 KillProcesses(executable_name, exit_code, filter); |
| 338 return exited_cleanly; | 338 return exited_cleanly; |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace base | 341 } // namespace base |
| OLD | NEW |