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> |
11 #include <sys/time.h> | 11 #include <sys/time.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 #include <sys/wait.h> | 13 #include <sys/wait.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
16 #include <limits> | 16 #include <limits> |
17 | 17 |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/platform_thread.h" | 20 #include "base/platform_thread.h" |
21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
22 #include "base/scoped_ptr.h" | 22 #include "base/scoped_ptr.h" |
23 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 | 25 |
26 const int kMicrosecondsPerSecond = 1000000; | 26 const int kMicrosecondsPerSecond = 1000000; |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 | 29 |
30 int GetCurrentProcId() { | 30 ProcessId GetCurrentProcId() { |
31 return getpid(); | 31 return getpid(); |
32 } | 32 } |
33 | 33 |
34 ProcessHandle GetCurrentProcessHandle() { | 34 ProcessHandle GetCurrentProcessHandle() { |
35 return GetCurrentProcId(); | 35 return GetCurrentProcId(); |
36 } | 36 } |
37 | 37 |
38 ProcessHandle OpenProcessHandle(int pid) { | 38 ProcessHandle OpenProcessHandle(ProcessId pid) { |
39 // On Posix platforms, process handles are the same as PIDs, so we | 39 // On Posix platforms, process handles are the same as PIDs, so we |
40 // don't need to do anything. | 40 // don't need to do anything. |
41 return pid; | 41 return pid; |
42 } | 42 } |
43 | 43 |
44 void CloseProcessHandle(ProcessHandle process) { | 44 void CloseProcessHandle(ProcessHandle process) { |
45 // See OpenProcessHandle, nothing to do. | 45 // See OpenProcessHandle, nothing to do. |
46 return; | 46 return; |
47 } | 47 } |
48 | 48 |
49 int GetProcId(ProcessHandle process) { | 49 ProcessId GetProcId(ProcessHandle process) { |
50 return process; | 50 return process; |
51 } | 51 } |
52 | 52 |
53 // Attempts to kill the process identified by the given process | 53 // Attempts to kill the process identified by the given process |
54 // entry structure. Ignores specified exit_code; posix can't force that. | 54 // entry structure. Ignores specified exit_code; posix can't force that. |
55 // Returns true if this is successful, false otherwise. | 55 // Returns true if this is successful, false otherwise. |
56 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { | 56 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { |
57 bool result = false; | 57 bool result = false; |
58 | 58 |
59 int status = kill(process_id, SIGTERM); | 59 int status = kill(process_id, SIGTERM); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 const ProcessFilter* filter) { | 361 const ProcessFilter* filter) { |
362 bool exited_cleanly = | 362 bool exited_cleanly = |
363 WaitForProcessesToExit(executable_name, wait_milliseconds, | 363 WaitForProcessesToExit(executable_name, wait_milliseconds, |
364 filter); | 364 filter); |
365 if (!exited_cleanly) | 365 if (!exited_cleanly) |
366 KillProcesses(executable_name, exit_code, filter); | 366 KillProcesses(executable_name, exit_code, filter); |
367 return exited_cleanly; | 367 return exited_cleanly; |
368 } | 368 } |
369 | 369 |
370 } // namespace base | 370 } // namespace base |
OLD | NEW |