| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 10 #pragma once |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 bool wait, ProcessHandle* process_handle); | 219 bool wait, ProcessHandle* process_handle); |
| 220 | 220 |
| 221 // Similar to the above, but also (un)set environment variables in child process | 221 // Similar to the above, but also (un)set environment variables in child process |
| 222 // through |environ|. | 222 // through |environ|. |
| 223 typedef std::vector<std::pair<std::string, std::string> > environment_vector; | 223 typedef std::vector<std::pair<std::string, std::string> > environment_vector; |
| 224 bool LaunchApp(const std::vector<std::string>& argv, | 224 bool LaunchApp(const std::vector<std::string>& argv, |
| 225 const environment_vector& environ, | 225 const environment_vector& environ, |
| 226 const file_handle_mapping_vector& fds_to_remap, | 226 const file_handle_mapping_vector& fds_to_remap, |
| 227 bool wait, ProcessHandle* process_handle); | 227 bool wait, ProcessHandle* process_handle); |
| 228 | 228 |
| 229 // Similar to the above two methods, but starts the child process in a process |
| 230 // group of its own, instead of allowing it to inherit the parent's process |
| 231 // group. The pgid of the child process will be the same as its pid. |
| 232 bool LaunchAppInNewProcessGroup(const std::vector<std::string>& argv, |
| 233 const environment_vector& environ, |
| 234 const file_handle_mapping_vector& fds_to_remap, |
| 235 bool wait, ProcessHandle* process_handle); |
| 236 |
| 229 // AlterEnvironment returns a modified environment vector, constructed from the | 237 // AlterEnvironment returns a modified environment vector, constructed from the |
| 230 // given environment and the list of changes given in |changes|. Each key in | 238 // given environment and the list of changes given in |changes|. Each key in |
| 231 // the environment is matched against the first element of the pairs. In the | 239 // the environment is matched against the first element of the pairs. In the |
| 232 // event of a match, the value is replaced by the second of the pair, unless | 240 // event of a match, the value is replaced by the second of the pair, unless |
| 233 // the second is empty, in which case the key-value is removed. | 241 // the second is empty, in which case the key-value is removed. |
| 234 // | 242 // |
| 235 // The returned array is allocated using new[] and must be freed by the caller. | 243 // The returned array is allocated using new[] and must be freed by the caller. |
| 236 char** AlterEnvironment(const environment_vector& changes, | 244 char** AlterEnvironment(const environment_vector& changes, |
| 237 const char* const* const env); | 245 const char* const* const env); |
| 238 #endif // defined(OS_POSIX) | 246 #endif // defined(OS_POSIX) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 269 | 277 |
| 270 // Returns the number of processes on the machine that are running from the | 278 // Returns the number of processes on the machine that are running from the |
| 271 // given executable name. If filter is non-null, then only processes selected | 279 // given executable name. If filter is non-null, then only processes selected |
| 272 // by the filter will be counted. | 280 // by the filter will be counted. |
| 273 int GetProcessCount(const std::wstring& executable_name, | 281 int GetProcessCount(const std::wstring& executable_name, |
| 274 const ProcessFilter* filter); | 282 const ProcessFilter* filter); |
| 275 | 283 |
| 276 // Attempts to kill all the processes on the current machine that were launched | 284 // Attempts to kill all the processes on the current machine that were launched |
| 277 // from the given executable name, ending them with the given exit code. If | 285 // from the given executable name, ending them with the given exit code. If |
| 278 // filter is non-null, then only processes selected by the filter are killed. | 286 // filter is non-null, then only processes selected by the filter are killed. |
| 279 // Returns false if all processes were able to be killed off, false if at least | 287 // Returns true if all processes were able to be killed off, false if at least |
| 280 // one couldn't be killed. | 288 // one couldn't be killed. |
| 281 bool KillProcesses(const std::wstring& executable_name, int exit_code, | 289 bool KillProcesses(const std::wstring& executable_name, int exit_code, |
| 282 const ProcessFilter* filter); | 290 const ProcessFilter* filter); |
| 283 | 291 |
| 284 // Attempts to kill the process identified by the given process | 292 // Attempts to kill the process identified by the given process |
| 285 // entry structure, giving it the specified exit code. If |wait| is true, wait | 293 // entry structure, giving it the specified exit code. If |wait| is true, wait |
| 286 // for the process to be actually terminated before returning. | 294 // for the process to be actually terminated before returning. |
| 287 // Returns true if this is successful, false otherwise. | 295 // Returns true if this is successful, false otherwise. |
| 288 bool KillProcess(ProcessHandle process, int exit_code, bool wait); | 296 bool KillProcess(ProcessHandle process, int exit_code, bool wait); |
| 297 |
| 298 #if defined(OS_POSIX) |
| 299 // Attempts to kill the process group identified by |process_group_id|. Returns |
| 300 // true on success. |
| 301 bool KillProcessGroup(ProcessHandle process_group_id); |
| 302 #endif |
| 303 |
| 289 #if defined(OS_WIN) | 304 #if defined(OS_WIN) |
| 290 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); | 305 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); |
| 291 #endif | 306 #endif |
| 292 | 307 |
| 293 // Get the termination status (exit code) of the process and return true if the | 308 // Get the termination status (exit code) of the process and return true if the |
| 294 // status indicates the process crashed. |child_exited| is set to true iff the | 309 // status indicates the process crashed. |child_exited| is set to true iff the |
| 295 // child process has terminated. (|child_exited| may be NULL.) | 310 // child process has terminated. (|child_exited| may be NULL.) |
| 296 bool DidProcessCrash(bool* child_exited, ProcessHandle handle); | 311 bool DidProcessCrash(bool* child_exited, ProcessHandle handle); |
| 297 | 312 |
| 298 // Waits for process to exit. In POSIX systems, if the process hasn't been | 313 // Waits for process to exit. In POSIX systems, if the process hasn't been |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 // instance running inside the parent. The parent's Breakpad instance should | 620 // instance running inside the parent. The parent's Breakpad instance should |
| 606 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 621 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
| 607 // in the child after forking will restore the standard exception handler. | 622 // in the child after forking will restore the standard exception handler. |
| 608 // See http://crbug.com/20371/ for more details. | 623 // See http://crbug.com/20371/ for more details. |
| 609 void RestoreDefaultExceptionHandler(); | 624 void RestoreDefaultExceptionHandler(); |
| 610 #endif // defined(OS_MACOSX) | 625 #endif // defined(OS_MACOSX) |
| 611 | 626 |
| 612 } // namespace base | 627 } // namespace base |
| 613 | 628 |
| 614 #endif // BASE_PROCESS_UTIL_H_ | 629 #endif // BASE_PROCESS_UTIL_H_ |
| OLD | NEW |