OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <dirent.h> | 8 #include <dirent.h> |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <fcntl.h> | 11 #include <fcntl.h> |
12 #include <sys/sysctl.h> | 12 #include <sys/sysctl.h> |
13 #include <sys/time.h> | 13 #include <sys/time.h> |
14 #include <sys/types.h> | 14 #include <sys/types.h> |
15 #include <sys/user.h> | 15 #include <sys/user.h> |
16 #include <sys/wait.h> | 16 #include <sys/wait.h> |
17 #include <time.h> | 17 #include <time.h> |
18 #include <unistd.h> | 18 #include <unistd.h> |
19 | 19 |
20 #include "base/file_util.h" | |
21 #include "base/logging.h" | 20 #include "base/logging.h" |
22 #include "base/string_tokenizer.h" | 21 #include "base/string_tokenizer.h" |
23 #include "base/string_util.h" | 22 #include "base/string_util.h" |
24 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
26 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
27 | 26 |
28 namespace base { | 27 namespace base { |
29 | 28 |
30 ProcessId GetParentProcessId(ProcessHandle process) { | 29 ProcessId GetParentProcessId(ProcessHandle process) { |
(...skipping 27 matching lines...) Expand all Loading... |
58 filter_(filter) { | 57 filter_(filter) { |
59 | 58 |
60 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid() }; | 59 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid() }; |
61 | 60 |
62 bool done = false; | 61 bool done = false; |
63 int try_num = 1; | 62 int try_num = 1; |
64 const int max_tries = 10; | 63 const int max_tries = 10; |
65 | 64 |
66 do { | 65 do { |
67 size_t len = 0; | 66 size_t len = 0; |
68 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) <0 ){ | 67 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0) { |
69 LOG(ERROR) << "failed to get the size needed for the process list"; | 68 LOG(ERROR) << "failed to get the size needed for the process list"; |
70 kinfo_procs_.resize(0); | 69 kinfo_procs_.resize(0); |
71 done = true; | 70 done = true; |
72 } else { | 71 } else { |
73 size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc); | 72 size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc); |
74 // Leave some spare room for process table growth (more could show up | 73 // Leave some spare room for process table growth (more could show up |
75 // between when we check and now) | 74 // between when we check and now) |
76 num_of_kinfo_proc += 16; | 75 num_of_kinfo_proc += 16; |
77 kinfo_procs_.resize(num_of_kinfo_proc); | 76 kinfo_procs_.resize(num_of_kinfo_proc); |
78 len = num_of_kinfo_proc * sizeof(struct kinfo_proc); | 77 len = num_of_kinfo_proc * sizeof(struct kinfo_proc); |
(...skipping 19 matching lines...) Expand all Loading... |
98 kinfo_procs_.resize(0); | 97 kinfo_procs_.resize(0); |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 ProcessIterator::~ProcessIterator() { | 101 ProcessIterator::~ProcessIterator() { |
103 } | 102 } |
104 | 103 |
105 bool ProcessIterator::CheckForNextProcess() { | 104 bool ProcessIterator::CheckForNextProcess() { |
106 std::string data; | 105 std::string data; |
107 | 106 |
108 for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++ index_of_kinfo_proc_) { | 107 for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++index_of_kinfo_proc_) { |
109 size_t length; | 108 size_t length; |
110 struct kinfo_proc kinfo = kinfo_procs_[index_of_kinfo_proc_]; | 109 struct kinfo_proc kinfo = kinfo_procs_[index_of_kinfo_proc_]; |
111 int mib[] = { CTL_KERN, KERN_PROC_ARGS, kinfo.ki_pid }; | 110 int mib[] = { CTL_KERN, KERN_PROC_ARGS, kinfo.ki_pid }; |
112 | 111 |
113 if ((kinfo.ki_pid > 0) && (kinfo.ki_stat == SZOMB)) | 112 if ((kinfo.ki_pid > 0) && (kinfo.ki_stat == SZOMB)) |
114 continue; | 113 continue; |
115 | 114 |
116 length = 0; | 115 length = 0; |
117 if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0) { | 116 if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0) { |
118 LOG(ERROR) << "failed to figure out the buffer size for a command line"; | 117 LOG(ERROR) << "failed to figure out the buffer size for a command line"; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 149 |
151 // Start w/ the next entry next time through | 150 // Start w/ the next entry next time through |
152 ++index_of_kinfo_proc_; | 151 ++index_of_kinfo_proc_; |
153 | 152 |
154 return true; | 153 return true; |
155 } | 154 } |
156 return false; | 155 return false; |
157 } | 156 } |
158 | 157 |
159 bool NamedProcessIterator::IncludeEntry() { | 158 bool NamedProcessIterator::IncludeEntry() { |
160 if(executable_name_ != entry().exe_file()) | 159 if (executable_name_ != entry().exe_file()) |
161 return false; | 160 return false; |
162 | 161 |
163 return ProcessIterator::IncludeEntry(); | 162 return ProcessIterator::IncludeEntry(); |
164 } | 163 } |
165 | 164 |
166 | 165 |
167 ProcessMetrics::ProcessMetrics(ProcessHandle process) | 166 ProcessMetrics::ProcessMetrics(ProcessHandle process) |
168 : process_(process), | 167 : process_(process), |
169 last_time_(0), | 168 last_time_(0), |
170 last_system_time_(0), | 169 last_system_time_(0), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void EnableTerminationOnHeapCorruption() { | 283 void EnableTerminationOnHeapCorruption() { |
285 // Nothing to do. | 284 // Nothing to do. |
286 } | 285 } |
287 | 286 |
288 bool AdjustOOMScore(ProcessId process, int score) { | 287 bool AdjustOOMScore(ProcessId process, int score) { |
289 NOTIMPLEMENTED(); | 288 NOTIMPLEMENTED(); |
290 return false; | 289 return false; |
291 } | 290 } |
292 | 291 |
293 } // namespace base | 292 } // namespace base |
OLD | NEW |