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_MACOSX) | 16 #elif defined(OS_MACOSX) |
17 // kinfo_proc is defined in <sys/sysctl.h>, but this forward declaration | 17 // kinfo_proc is defined in <sys/sysctl.h>, but this forward declaration |
18 // is sufficient for the vector<kinfo_proc> below. | 18 // is sufficient for the vector<kinfo_proc> below. |
19 struct kinfo_proc; | 19 struct kinfo_proc; |
| 20 #include <mach/mach.h> |
20 #elif defined(OS_POSIX) | 21 #elif defined(OS_POSIX) |
21 #include <dirent.h> | 22 #include <dirent.h> |
22 #include <limits.h> | 23 #include <limits.h> |
23 #include <sys/types.h> | 24 #include <sys/types.h> |
24 #endif | 25 #endif |
25 | 26 |
26 #include <string> | 27 #include <string> |
27 #include <utility> | 28 #include <utility> |
28 #include <vector> | 29 #include <vector> |
29 | 30 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // As above, if wait is true, execute synchronously. The pid will be stored | 149 // As above, if wait is true, execute synchronously. The pid will be stored |
149 // in process_handle if that pointer is non-null. | 150 // in process_handle if that pointer is non-null. |
150 // | 151 // |
151 // Note that the first argument in argv must point to the executable filename. | 152 // Note that the first argument in argv must point to the executable filename. |
152 // If the filename is not fully specified, PATH will be searched. | 153 // If the filename is not fully specified, PATH will be searched. |
153 typedef std::vector<std::pair<int, int> > file_handle_mapping_vector; | 154 typedef std::vector<std::pair<int, int> > file_handle_mapping_vector; |
154 bool LaunchApp(const std::vector<std::string>& argv, | 155 bool LaunchApp(const std::vector<std::string>& argv, |
155 const file_handle_mapping_vector& fds_to_remap, | 156 const file_handle_mapping_vector& fds_to_remap, |
156 bool wait, ProcessHandle* process_handle); | 157 bool wait, ProcessHandle* process_handle); |
157 | 158 |
158 // Similar to above, but also (un)set environment variables in child process | 159 // Similar to the above, but also (un)set environment variables in child process |
159 // through |environ|. | 160 // through |environ|. |
160 typedef std::vector<std::pair<std::string, std::string> > environment_vector; | 161 typedef std::vector<std::pair<std::string, std::string> > environment_vector; |
161 bool LaunchApp(const std::vector<std::string>& argv, | 162 bool LaunchApp(const std::vector<std::string>& argv, |
162 const environment_vector& environ, | 163 const environment_vector& environ, |
163 const file_handle_mapping_vector& fds_to_remap, | 164 const file_handle_mapping_vector& fds_to_remap, |
164 bool wait, ProcessHandle* process_handle); | 165 bool wait, ProcessHandle* process_handle); |
| 166 |
| 167 #if defined(OS_MACOSX) |
| 168 // Similar to the above, but also returns the new process's task_t if |
| 169 // |task_handle| is not NULL. If |task_handle| is not NULL, the caller is |
| 170 // responsible for calling |vm_deallocate()| on the returned handle. |
| 171 bool LaunchAppAndGetTask(const std::vector<std::string>& argv, |
| 172 const environment_vector& environ, |
| 173 const file_handle_mapping_vector& fds_to_remap, |
| 174 bool wait, |
| 175 task_t* task_handle, |
| 176 ProcessHandle* process_handle); |
| 177 #endif // defined(OS_MACOSX) |
165 #endif // defined(OS_POSIX) | 178 #endif // defined(OS_POSIX) |
166 | 179 |
167 // Executes the application specified by cl. This function delegates to one | 180 // Executes the application specified by cl. This function delegates to one |
168 // of the above two platform-specific functions. | 181 // of the above two platform-specific functions. |
169 bool LaunchApp(const CommandLine& cl, | 182 bool LaunchApp(const CommandLine& cl, |
170 bool wait, bool start_hidden, ProcessHandle* process_handle); | 183 bool wait, bool start_hidden, ProcessHandle* process_handle); |
171 | 184 |
172 // Executes the application specified by |cl| and wait for it to exit. Stores | 185 // Executes the application specified by |cl| and wait for it to exit. Stores |
173 // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true | 186 // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true |
174 // on success (application launched and exited cleanly, with exit code | 187 // on success (application launched and exited cleanly, with exit code |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 // instance running inside the parent. The parent's Breakpad instance should | 512 // instance running inside the parent. The parent's Breakpad instance should |
500 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 513 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
501 // in the child after forking will restore the standard exception handler. | 514 // in the child after forking will restore the standard exception handler. |
502 // See http://crbug.com/20371/ for more details. | 515 // See http://crbug.com/20371/ for more details. |
503 void RestoreDefaultExceptionHandler(); | 516 void RestoreDefaultExceptionHandler(); |
504 #endif | 517 #endif |
505 | 518 |
506 } // namespace base | 519 } // namespace base |
507 | 520 |
508 #endif // BASE_PROCESS_UTIL_H_ | 521 #endif // BASE_PROCESS_UTIL_H_ |
OLD | NEW |