Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2170)

Unified Diff: base/process_util_linux.cc

Issue 119289: Enable zygote manager by default. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_linux.cc
===================================================================
--- base/process_util_linux.cc (revision 17847)
+++ base/process_util_linux.cc (working copy)
@@ -7,10 +7,10 @@
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
-#include <unistd.h>
#include <string>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include "base/eintr_wrapper.h"
#include "base/file_util.h"
@@ -42,6 +42,50 @@
namespace base {
+ProcessId GetParentProcessId(ProcessHandle process) {
+ FilePath stat_file("/proc");
+ stat_file = stat_file.Append(IntToString(process));
+ stat_file = stat_file.Append("status");
+ std::string status;
+ if (!file_util::ReadFileToString(stat_file, &status))
+ return -1;
+
+ StringTokenizer tokenizer(status, ":\n");
+ ParsingState state = KEY_NAME;
+ std::string last_key_name;
+ while (tokenizer.GetNext()) {
+ switch (state) {
+ case KEY_NAME:
+ last_key_name = tokenizer.token();
+ state = KEY_VALUE;
+ break;
+ case KEY_VALUE:
+ DCHECK(!last_key_name.empty());
+ if (last_key_name == "PPid") {
+ pid_t ppid = StringToInt(tokenizer.token());
+ return ppid;
+ }
+ state = KEY_NAME;
+ break;
+ }
+ }
+ NOTREACHED();
+ return -1;
+}
+
+FilePath GetProcessExecutablePath(ProcessHandle process) {
+ FilePath stat_file("/proc");
+ stat_file = stat_file.Append(IntToString(process));
+ stat_file = stat_file.Append("exe");
+ char exename[2048];
+ ssize_t len = readlink(stat_file.value().c_str(), exename, sizeof(exename));
+ if (len < 1) {
+ // No such process. Happens frequently in e.g. TerminateAllChromeProcesses
+ return FilePath();
+ }
+ return FilePath(std::string(exename, len));
+}
+
bool ForkApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
ProcessHandle* process_handle) {
« no previous file with comments | « base/process_util.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698