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 16 matching lines...) Expand all Loading... |
27 #include <limits.h> | 27 #include <limits.h> |
28 #include <sys/types.h> | 28 #include <sys/types.h> |
29 #endif | 29 #endif |
30 | 30 |
31 #include <list> | 31 #include <list> |
32 #include <string> | 32 #include <string> |
33 #include <utility> | 33 #include <utility> |
34 #include <vector> | 34 #include <vector> |
35 | 35 |
36 #include "base/file_descriptor_shuffle.h" | 36 #include "base/file_descriptor_shuffle.h" |
| 37 #include "base/file_path.h" |
37 #include "base/process.h" | 38 #include "base/process.h" |
38 | 39 |
39 class CommandLine; | 40 class CommandLine; |
40 class FilePath; | |
41 | 41 |
42 namespace base { | 42 namespace base { |
43 | 43 |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 struct ProcessEntry : public PROCESSENTRY32 { | 45 struct ProcessEntry : public PROCESSENTRY32 { |
46 ProcessId pid() const { return th32ProcessID; } | 46 ProcessId pid() const { return th32ProcessID; } |
47 ProcessId parent_pid() const { return th32ParentProcessID; } | 47 ProcessId parent_pid() const { return th32ParentProcessID; } |
48 const wchar_t* exe_file() const { return szExeFile; } | 48 const wchar_t* exe_file() const { return szExeFile; } |
49 }; | 49 }; |
50 | 50 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // should not have side-effects and should be idempotent. | 315 // should not have side-effects and should be idempotent. |
316 virtual bool Includes(const ProcessEntry& entry) const = 0; | 316 virtual bool Includes(const ProcessEntry& entry) const = 0; |
317 | 317 |
318 protected: | 318 protected: |
319 virtual ~ProcessFilter() {} | 319 virtual ~ProcessFilter() {} |
320 }; | 320 }; |
321 | 321 |
322 // Returns the number of processes on the machine that are running from the | 322 // Returns the number of processes on the machine that are running from the |
323 // given executable name. If filter is non-null, then only processes selected | 323 // given executable name. If filter is non-null, then only processes selected |
324 // by the filter will be counted. | 324 // by the filter will be counted. |
325 int GetProcessCount(const std::wstring& executable_name, | 325 int GetProcessCount(const FilePath::StringType& executable_name, |
326 const ProcessFilter* filter); | 326 const ProcessFilter* filter); |
327 | 327 |
328 // Attempts to kill all the processes on the current machine that were launched | 328 // Attempts to kill all the processes on the current machine that were launched |
329 // from the given executable name, ending them with the given exit code. If | 329 // from the given executable name, ending them with the given exit code. If |
330 // filter is non-null, then only processes selected by the filter are killed. | 330 // filter is non-null, then only processes selected by the filter are killed. |
331 // Returns true if all processes were able to be killed off, false if at least | 331 // Returns true if all processes were able to be killed off, false if at least |
332 // one couldn't be killed. | 332 // one couldn't be killed. |
333 bool KillProcesses(const std::wstring& executable_name, int exit_code, | 333 bool KillProcesses(const FilePath::StringType& executable_name, int exit_code, |
334 const ProcessFilter* filter); | 334 const ProcessFilter* filter); |
335 | 335 |
336 // Attempts to kill the process identified by the given process | 336 // Attempts to kill the process identified by the given process |
337 // entry structure, giving it the specified exit code. If |wait| is true, wait | 337 // entry structure, giving it the specified exit code. If |wait| is true, wait |
338 // for the process to be actually terminated before returning. | 338 // for the process to be actually terminated before returning. |
339 // Returns true if this is successful, false otherwise. | 339 // Returns true if this is successful, false otherwise. |
340 bool KillProcess(ProcessHandle process, int exit_code, bool wait); | 340 bool KillProcess(ProcessHandle process, int exit_code, bool wait); |
341 | 341 |
342 #if defined(OS_POSIX) | 342 #if defined(OS_POSIX) |
343 // Attempts to kill the process group identified by |process_group_id|. Returns | 343 // Attempts to kill the process group identified by |process_group_id|. Returns |
(...skipping 26 matching lines...) Expand all Loading... |
370 // In POSIX systems, if the process has been signaled then |exit_code| is set | 370 // In POSIX systems, if the process has been signaled then |exit_code| is set |
371 // to -1. Returns false on failure (the caller is then responsible for closing | 371 // to -1. Returns false on failure (the caller is then responsible for closing |
372 // |handle|). | 372 // |handle|). |
373 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, | 373 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, |
374 int64 timeout_milliseconds); | 374 int64 timeout_milliseconds); |
375 | 375 |
376 // Wait for all the processes based on the named executable to exit. If filter | 376 // Wait for all the processes based on the named executable to exit. If filter |
377 // is non-null, then only processes selected by the filter are waited on. | 377 // is non-null, then only processes selected by the filter are waited on. |
378 // Returns after all processes have exited or wait_milliseconds have expired. | 378 // Returns after all processes have exited or wait_milliseconds have expired. |
379 // Returns true if all the processes exited, false otherwise. | 379 // Returns true if all the processes exited, false otherwise. |
380 bool WaitForProcessesToExit(const std::wstring& executable_name, | 380 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, |
381 int64 wait_milliseconds, | 381 int64 wait_milliseconds, |
382 const ProcessFilter* filter); | 382 const ProcessFilter* filter); |
383 | 383 |
384 // Wait for a single process to exit. Return true if it exited cleanly within | 384 // Wait for a single process to exit. Return true if it exited cleanly within |
385 // the given time limit. | 385 // the given time limit. |
386 bool WaitForSingleProcess(ProcessHandle handle, | 386 bool WaitForSingleProcess(ProcessHandle handle, |
387 int64 wait_milliseconds); | 387 int64 wait_milliseconds); |
388 | 388 |
389 // Returns true when |wait_milliseconds| have elapsed and the process | 389 // Returns true when |wait_milliseconds| have elapsed and the process |
390 // is still running. | 390 // is still running. |
391 bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds); | 391 bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds); |
392 | 392 |
393 // Waits a certain amount of time (can be 0) for all the processes with a given | 393 // Waits a certain amount of time (can be 0) for all the processes with a given |
394 // executable name to exit, then kills off any of them that are still around. | 394 // executable name to exit, then kills off any of them that are still around. |
395 // If filter is non-null, then only processes selected by the filter are waited | 395 // If filter is non-null, then only processes selected by the filter are waited |
396 // on. Killed processes are ended with the given exit code. Returns false if | 396 // on. Killed processes are ended with the given exit code. Returns false if |
397 // any processes needed to be killed, true if they all exited cleanly within | 397 // any processes needed to be killed, true if they all exited cleanly within |
398 // the wait_milliseconds delay. | 398 // the wait_milliseconds delay. |
399 bool CleanupProcesses(const std::wstring& executable_name, | 399 bool CleanupProcesses(const FilePath::StringType& executable_name, |
400 int64 wait_milliseconds, | 400 int64 wait_milliseconds, |
401 int exit_code, | 401 int exit_code, |
402 const ProcessFilter* filter); | 402 const ProcessFilter* filter); |
403 | 403 |
404 // This class provides a way to iterate through a list of processes on the | 404 // This class provides a way to iterate through a list of processes on the |
405 // current machine with a specified filter. | 405 // current machine with a specified filter. |
406 // To use, create an instance and then call NextProcessEntry() until it returns | 406 // To use, create an instance and then call NextProcessEntry() until it returns |
407 // false. | 407 // false. |
408 class ProcessIterator { | 408 class ProcessIterator { |
409 public: | 409 public: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 450 |
451 DISALLOW_COPY_AND_ASSIGN(ProcessIterator); | 451 DISALLOW_COPY_AND_ASSIGN(ProcessIterator); |
452 }; | 452 }; |
453 | 453 |
454 // This class provides a way to iterate through the list of processes | 454 // This class provides a way to iterate through the list of processes |
455 // on the current machine that were started from the given executable | 455 // on the current machine that were started from the given executable |
456 // name. To use, create an instance and then call NextProcessEntry() | 456 // name. To use, create an instance and then call NextProcessEntry() |
457 // until it returns false. | 457 // until it returns false. |
458 class NamedProcessIterator : public ProcessIterator { | 458 class NamedProcessIterator : public ProcessIterator { |
459 public: | 459 public: |
460 NamedProcessIterator(const std::wstring& executable_name, | 460 NamedProcessIterator(const FilePath::StringType& executable_name, |
461 const ProcessFilter* filter); | 461 const ProcessFilter* filter); |
462 virtual ~NamedProcessIterator(); | 462 virtual ~NamedProcessIterator(); |
463 | 463 |
464 protected: | 464 protected: |
465 virtual bool IncludeEntry(); | 465 virtual bool IncludeEntry(); |
466 | 466 |
467 private: | 467 private: |
468 std::wstring executable_name_; | 468 FilePath::StringType executable_name_; |
469 | 469 |
470 DISALLOW_COPY_AND_ASSIGN(NamedProcessIterator); | 470 DISALLOW_COPY_AND_ASSIGN(NamedProcessIterator); |
471 }; | 471 }; |
472 | 472 |
473 // Working Set (resident) memory usage broken down by | 473 // Working Set (resident) memory usage broken down by |
474 // | 474 // |
475 // On Windows: | 475 // On Windows: |
476 // priv (private): These pages (kbytes) cannot be shared with any other process. | 476 // priv (private): These pages (kbytes) cannot be shared with any other process. |
477 // shareable: These pages (kbytes) can be shared with other processes under | 477 // shareable: These pages (kbytes) can be shared with other processes under |
478 // the right circumstances. | 478 // the right circumstances. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 // instance running inside the parent. The parent's Breakpad instance should | 669 // instance running inside the parent. The parent's Breakpad instance should |
670 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 670 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
671 // in the child after forking will restore the standard exception handler. | 671 // in the child after forking will restore the standard exception handler. |
672 // See http://crbug.com/20371/ for more details. | 672 // See http://crbug.com/20371/ for more details. |
673 void RestoreDefaultExceptionHandler(); | 673 void RestoreDefaultExceptionHandler(); |
674 #endif // defined(OS_MACOSX) | 674 #endif // defined(OS_MACOSX) |
675 | 675 |
676 } // namespace base | 676 } // namespace base |
677 | 677 |
678 #endif // BASE_PROCESS_UTIL_H_ | 678 #endif // BASE_PROCESS_UTIL_H_ |
OLD | NEW |