diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-04 16:17:13 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-04 16:17:13 +0000 |
commit | 983ef7fa2d5b27f1fa5b8d338ffde33fe24d72f3 (patch) | |
tree | 2fe6bde0f39073108f4ce1d152d130eb92d58b38 /chrome/browser/process_info_snapshot_mac.cc | |
parent | 6ce8ba65f2767fcabec600bf4c0022e0022c16cb (diff) | |
download | chromium_src-983ef7fa2d5b27f1fa5b8d338ffde33fe24d72f3.zip chromium_src-983ef7fa2d5b27f1fa5b8d338ffde33fe24d72f3.tar.gz chromium_src-983ef7fa2d5b27f1fa5b8d338ffde33fe24d72f3.tar.bz2 |
Mac: stop zombie ps processes from being created.
This fixes two bugs:
- the output buffer for the ps command being run could be too small (fix: buffer
enlargened); and
- if the output buffer was too small, waitpid() wouldn't be called (fix: always
call waitpid(), obviously).
BUG=31378
TEST=On a big, long-running Chrome/Chromium (with many processes, e.g., renderers), check that there are no zombie ps processes (with PPID the browser process); looking at about:memory may help speed up the creation of such zombies. Also, run the new test, ProcessUtilTest.GetAppOutputRestrictedNoZombies.
Review URL: http://codereview.chromium.org/523033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_info_snapshot_mac.cc')
-rw-r--r-- | chrome/browser/process_info_snapshot_mac.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/chrome/browser/process_info_snapshot_mac.cc b/chrome/browser/process_info_snapshot_mac.cc index 611f8f4..4e2608b 100644 --- a/chrome/browser/process_info_snapshot_mac.cc +++ b/chrome/browser/process_info_snapshot_mac.cc @@ -7,6 +7,7 @@ #include <iostream> #include <sstream> +#include "base/logging.h" #include "base/string_util.h" #include "base/thread.h" @@ -21,6 +22,8 @@ ProcessInfoSnapshot::~ProcessInfoSnapshot() { Reset(); } +const size_t ProcessInfoSnapshot::kMaxPidListSize = 1000; + // Capture the information by calling '/bin/ps'. // Note: we ignore the "tsiz" (text size) display option of ps because it's // always zero (tested on 10.5 and 10.6). @@ -28,6 +31,15 @@ bool ProcessInfoSnapshot::Sample(std::vector<base::ProcessId> pid_list) { const char* kPsPathName = "/bin/ps"; Reset(); + // Nothing to do if no PIDs given. + if (pid_list.size() == 0) + return true; + if (pid_list.size() > kMaxPidListSize) { + // The spec says |pid_list| *must* not have more than this many entries. + NOTREACHED(); + return false; + } + std::vector<std::string> argv; argv.push_back(kPsPathName); // Get PID, PPID, (real) UID, effective UID, resident set size, virtual memory @@ -43,8 +55,8 @@ bool ProcessInfoSnapshot::Sample(std::vector<base::ProcessId> pid_list) { std::string output; CommandLine command_line(argv); - if (!base::GetAppOutputRestricted(command_line, - &output, (pid_list.size() + 10) * 100)) { + // Limit output read to a megabyte for safety. + if (!base::GetAppOutputRestricted(command_line, &output, 1024 * 1024)) { LOG(ERROR) << "Failure running " << kPsPathName << " to acquire data."; return false; } |