| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This file/namespace contains utility functions for enumerating, ending and | 5 // This file/namespace contains utility functions for enumerating, ending and |
| 6 // computing statistics of processes. | 6 // computing statistics of processes. |
| 7 | 7 |
| 8 #ifndef BASE_PROCESS_UTIL_H_ | 8 #ifndef BASE_PROCESS_UTIL_H_ |
| 9 #define BASE_PROCESS_UTIL_H_ | 9 #define BASE_PROCESS_UTIL_H_ |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
| 14 #include <windows.h> | 14 #include <windows.h> |
| 15 #include <tlhelp32.h> | 15 #include <tlhelp32.h> |
| 16 #elif defined(OS_LINUX) | 16 #elif defined(OS_LINUX) |
| 17 #include <dirent.h> | 17 #include <dirent.h> |
| 18 #include <limits.h> | 18 #include <limits.h> |
| 19 #include <sys/types.h> | 19 #include <sys/types.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #include <string> | 22 #include <string> |
| 23 #include <utility> |
| 23 #include <vector> | 24 #include <vector> |
| 24 | 25 |
| 25 #include "base/command_line.h" | 26 #include "base/command_line.h" |
| 26 #include "base/file_path.h" | 27 #include "base/file_path.h" |
| 27 #include "base/process.h" | 28 #include "base/process.h" |
| 28 | 29 |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 typedef PROCESSENTRY32 ProcessEntry; | 31 typedef PROCESSENTRY32 ProcessEntry; |
| 31 typedef IO_COUNTERS IoCounters; | 32 typedef IO_COUNTERS IoCounters; |
| 32 #elif defined(OS_POSIX) | 33 #elif defined(OS_POSIX) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // | 135 // |
| 135 // As above, if wait is true, execute synchronously. The pid will be stored | 136 // As above, if wait is true, execute synchronously. The pid will be stored |
| 136 // in process_handle if that pointer is non-null. | 137 // in process_handle if that pointer is non-null. |
| 137 // | 138 // |
| 138 // Note that the first argument in argv must point to the executable filename. | 139 // Note that the first argument in argv must point to the executable filename. |
| 139 // If the filename is not fully specified, PATH will be searched. | 140 // If the filename is not fully specified, PATH will be searched. |
| 140 typedef std::vector<std::pair<int, int> > file_handle_mapping_vector; | 141 typedef std::vector<std::pair<int, int> > file_handle_mapping_vector; |
| 141 bool LaunchApp(const std::vector<std::string>& argv, | 142 bool LaunchApp(const std::vector<std::string>& argv, |
| 142 const file_handle_mapping_vector& fds_to_remap, | 143 const file_handle_mapping_vector& fds_to_remap, |
| 143 bool wait, ProcessHandle* process_handle); | 144 bool wait, ProcessHandle* process_handle); |
| 144 #endif | 145 #if defined(OS_LINUX) |
| 146 // Similar to above, but also (un)set environment variables in child process |
| 147 // through |environ|. |
| 148 typedef std::vector<std::pair<const char*, const char*> > environment_vector; |
| 149 bool LaunchApp(const std::vector<std::string>& argv, |
| 150 const environment_vector& environ, |
| 151 const file_handle_mapping_vector& fds_to_remap, |
| 152 bool wait, ProcessHandle* process_handle); |
| 153 #endif // defined(OS_LINUX) |
| 154 #endif // defined(OS_POSIX) |
| 145 | 155 |
| 146 // Executes the application specified by cl. This function delegates to one | 156 // Executes the application specified by cl. This function delegates to one |
| 147 // of the above two platform-specific functions. | 157 // of the above two platform-specific functions. |
| 148 bool LaunchApp(const CommandLine& cl, | 158 bool LaunchApp(const CommandLine& cl, |
| 149 bool wait, bool start_hidden, ProcessHandle* process_handle); | 159 bool wait, bool start_hidden, ProcessHandle* process_handle); |
| 150 | 160 |
| 151 // Executes the application specified by |cl| and wait for it to exit. Stores | 161 // Executes the application specified by |cl| and wait for it to exit. Stores |
| 152 // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true | 162 // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true |
| 153 // on success (application launched and exited cleanly, with exit code | 163 // on success (application launched and exited cleanly, with exit code |
| 154 // indicating success). |output| is modified only when the function finished | 164 // indicating success). |output| is modified only when the function finished |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // overflow. Has no effect if the OS doesn't provide the necessary facility. | 402 // overflow. Has no effect if the OS doesn't provide the necessary facility. |
| 393 void EnableTerminationOnHeapCorruption(); | 403 void EnableTerminationOnHeapCorruption(); |
| 394 | 404 |
| 395 // If supported on the platform, and the user has sufficent rights, increase | 405 // If supported on the platform, and the user has sufficent rights, increase |
| 396 // the current process's scheduling priority to a high priority. | 406 // the current process's scheduling priority to a high priority. |
| 397 void RaiseProcessToHighPriority(); | 407 void RaiseProcessToHighPriority(); |
| 398 | 408 |
| 399 } // namespace base | 409 } // namespace base |
| 400 | 410 |
| 401 #endif // BASE_PROCESS_UTIL_H_ | 411 #endif // BASE_PROCESS_UTIL_H_ |
| OLD | NEW |