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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/process_util.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 #include "base/process_util.h" 5 #include "base/process_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <dirent.h> 8 #include <dirent.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <string> 10 #include <string>
12 #include <sys/types.h> 11 #include <sys/types.h>
13 #include <sys/wait.h> 12 #include <sys/wait.h>
13 #include <unistd.h>
14 14
15 #include "base/eintr_wrapper.h" 15 #include "base/eintr_wrapper.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/string_tokenizer.h" 18 #include "base/string_tokenizer.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/zygote_manager.h" 20 #include "base/zygote_manager.h"
21 21
22 namespace { 22 namespace {
23 23
(...skipping 11 matching lines...) Expand all
35 std::string mem_stats; 35 std::string mem_stats;
36 if (!file_util::ReadFileToString(stat_file, &mem_stats)) 36 if (!file_util::ReadFileToString(stat_file, &mem_stats))
37 return; 37 return;
38 SplitString(mem_stats, ' ', proc_stats); 38 SplitString(mem_stats, ' ', proc_stats);
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 namespace base { 43 namespace base {
44 44
45 ProcessId GetParentProcessId(ProcessHandle process) {
46 FilePath stat_file("/proc");
47 stat_file = stat_file.Append(IntToString(process));
48 stat_file = stat_file.Append("status");
49 std::string status;
50 if (!file_util::ReadFileToString(stat_file, &status))
51 return -1;
52
53 StringTokenizer tokenizer(status, ":\n");
54 ParsingState state = KEY_NAME;
55 std::string last_key_name;
56 while (tokenizer.GetNext()) {
57 switch (state) {
58 case KEY_NAME:
59 last_key_name = tokenizer.token();
60 state = KEY_VALUE;
61 break;
62 case KEY_VALUE:
63 DCHECK(!last_key_name.empty());
64 if (last_key_name == "PPid") {
65 pid_t ppid = StringToInt(tokenizer.token());
66 return ppid;
67 }
68 state = KEY_NAME;
69 break;
70 }
71 }
72 NOTREACHED();
73 return -1;
74 }
75
76 FilePath GetProcessExecutablePath(ProcessHandle process) {
77 FilePath stat_file("/proc");
78 stat_file = stat_file.Append(IntToString(process));
79 stat_file = stat_file.Append("exe");
80 char exename[2048];
81 ssize_t len = readlink(stat_file.value().c_str(), exename, sizeof(exename));
82 if (len < 1) {
83 // No such process. Happens frequently in e.g. TerminateAllChromeProcesses
84 return FilePath();
85 }
86 return FilePath(std::string(exename, len));
87 }
88
45 bool ForkApp(const std::vector<std::string>& argv, 89 bool ForkApp(const std::vector<std::string>& argv,
46 const file_handle_mapping_vector& fds_to_remap, 90 const file_handle_mapping_vector& fds_to_remap,
47 ProcessHandle* process_handle) { 91 ProcessHandle* process_handle) {
48 ZygoteManager* zm = ZygoteManager::Get(); 92 ZygoteManager* zm = ZygoteManager::Get();
49 if (!zm) 93 if (!zm)
50 return LaunchApp(argv, fds_to_remap, false, process_handle); 94 return LaunchApp(argv, fds_to_remap, false, process_handle);
51 95
52 pid_t pid = zm->LongFork(argv, fds_to_remap); 96 pid_t pid = zm->LongFork(argv, fds_to_remap);
53 if (pid < 0) 97 if (pid < 0)
54 return false; 98 return false;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); 338 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token());
295 } 339 }
296 state = KEY_NAME; 340 state = KEY_NAME;
297 break; 341 break;
298 } 342 }
299 } 343 }
300 return true; 344 return true;
301 } 345 }
302 346
303 } // namespace base 347 } // namespace base
OLDNEW
« 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