| Index: base/process_util_posix.cc
|
| ===================================================================
|
| --- base/process_util_posix.cc (revision 9017)
|
| +++ base/process_util_posix.cc (working copy)
|
| @@ -17,6 +17,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/logging.h"
|
| +#include "base/platform_thread.h"
|
| #include "base/process_util.h"
|
| #include "base/sys_info.h"
|
| #include "base/time.h"
|
| @@ -270,4 +271,60 @@
|
| return cpu;
|
| }
|
|
|
| +int GetProcessCount(const std::wstring& executable_name,
|
| + const ProcessFilter* filter) {
|
| + int count = 0;
|
| +
|
| + NamedProcessIterator iter(executable_name, filter);
|
| + while (iter.NextProcessEntry())
|
| + ++count;
|
| + return count;
|
| +}
|
| +
|
| +bool KillProcesses(const std::wstring& executable_name, int exit_code,
|
| + const ProcessFilter* filter) {
|
| + bool result = true;
|
| + const ProcessEntry* entry;
|
| +
|
| + NamedProcessIterator iter(executable_name, filter);
|
| + while ((entry = iter.NextProcessEntry()) != NULL)
|
| + result = KillProcess((*entry).pid, exit_code, true) && result;
|
| +
|
| + return result;
|
| +}
|
| +
|
| +bool WaitForProcessesToExit(const std::wstring& executable_name,
|
| + int wait_milliseconds,
|
| + const ProcessFilter* filter) {
|
| + bool result = false;
|
| +
|
| + // TODO(port): This is inefficient, but works if there are multiple procs.
|
| + // TODO(port): use waitpid to avoid leaving zombies around
|
| +
|
| + base::Time end_time = base::Time::Now() +
|
| + base::TimeDelta::FromMilliseconds(wait_milliseconds);
|
| + do {
|
| + NamedProcessIterator iter(executable_name, filter);
|
| + if (!iter.NextProcessEntry()) {
|
| + result = true;
|
| + break;
|
| + }
|
| + PlatformThread::Sleep(100);
|
| + } while ((base::Time::Now() - end_time) > base::TimeDelta());
|
| +
|
| + return result;
|
| +}
|
| +
|
| +bool CleanupProcesses(const std::wstring& executable_name,
|
| + int wait_milliseconds,
|
| + int exit_code,
|
| + const ProcessFilter* filter) {
|
| + bool exited_cleanly =
|
| + WaitForProcessesToExit(executable_name, wait_milliseconds,
|
| + filter);
|
| + if (!exited_cleanly)
|
| + KillProcesses(executable_name, exit_code, filter);
|
| + return exited_cleanly;
|
| +}
|
| +
|
| } // namespace base
|
|
|