maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
| 5 | // This file/namespace contains utility functions for enumerating, ending and |
| 6 | // computing statistics of processes. |
| 7 | |
deanm@google.com | db71728 | 2008-08-27 13:48:03 | [diff] [blame] | 8 | #ifndef BASE_PROCESS_UTIL_H_ |
| 9 | #define BASE_PROCESS_UTIL_H_ |
thakis@chromium.org | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 10 | #pragma once |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 11 | |
paulg@google.com | 6165906 | 2008-08-06 01:04:18 | [diff] [blame] | 12 | #include "base/basictypes.h" |
| 13 | |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 14 | #if defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 15 | #include <windows.h> |
| 16 | #include <tlhelp32.h> |
wtc@chromium.org | 4a34ce0 | 2009-08-31 22:25:00 | [diff] [blame] | 17 | #elif defined(OS_MACOSX) |
| 18 | // kinfo_proc is defined in <sys/sysctl.h>, but this forward declaration |
| 19 | // is sufficient for the vector<kinfo_proc> below. |
| 20 | struct kinfo_proc; |
avi@chromium.org | 6cfa339 | 2010-07-01 20:11:43 | [diff] [blame] | 21 | // malloc_zone_t is defined in <malloc/malloc.h>, but this forward declaration |
| 22 | // is sufficient for GetPurgeableZone() below. |
| 23 | typedef struct _malloc_zone_t malloc_zone_t; |
thakis@chromium.org | c002879 | 2010-01-12 00:39:15 | [diff] [blame] | 24 | #include <mach/mach.h> |
wtc@chromium.org | 4a34ce0 | 2009-08-31 22:25:00 | [diff] [blame] | 25 | #elif defined(OS_POSIX) |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 26 | #include <dirent.h> |
| 27 | #include <limits.h> |
| 28 | #include <sys/types.h> |
paulg@google.com | 6165906 | 2008-08-06 01:04:18 | [diff] [blame] | 29 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 30 | |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 31 | #include <list> |
paulg@google.com | 6165906 | 2008-08-06 01:04:18 | [diff] [blame] | 32 | #include <string> |
thestig@chromium.org | 9ec8db0 | 2009-07-21 07:00:13 | [diff] [blame] | 33 | #include <utility> |
mark@chromium.org | 962dd31 | 2009-02-05 21:44:13 | [diff] [blame] | 34 | #include <vector> |
paulg@google.com | 6165906 | 2008-08-06 01:04:18 | [diff] [blame] | 35 | |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 36 | #include "base/file_descriptor_shuffle.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 37 | #include "base/process.h" |
| 38 | |
evan@chromium.org | 93f21e4 | 2010-04-01 00:35:15 | [diff] [blame] | 39 | #ifndef NAME_MAX // Solaris and some BSDs have no NAME_MAX |
| 40 | #ifdef MAXNAMLEN |
| 41 | #define NAME_MAX MAXNAMLEN |
| 42 | #else |
| 43 | #define NAME_MAX 256 |
| 44 | #endif |
| 45 | #endif |
| 46 | |
erg@google.com | 5d91c9e | 2010-07-28 17:25:28 | [diff] [blame] | 47 | class CommandLine; |
| 48 | class FilePath; |
| 49 | |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 50 | namespace base { |
| 51 | |
paulg@google.com | 6165906 | 2008-08-06 01:04:18 | [diff] [blame] | 52 | #if defined(OS_WIN) |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 53 | |
| 54 | struct ProcessEntry : public PROCESSENTRY32 { |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 55 | ProcessId pid() const { return th32ProcessID; } |
| 56 | ProcessId parent_pid() const { return th32ParentProcessID; } |
| 57 | const wchar_t* exe_file() const { return szExeFile; } |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 58 | }; |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 59 | |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 60 | struct IoCounters : public IO_COUNTERS { |
| 61 | }; |
| 62 | |
paulg@google.com | 6165906 | 2008-08-06 01:04:18 | [diff] [blame] | 63 | #elif defined(OS_POSIX) |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 64 | |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 65 | struct ProcessEntry { |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 66 | ProcessId pid_; |
| 67 | ProcessId ppid_; |
| 68 | ProcessId gid_; |
| 69 | std::string exe_file_; |
| 70 | |
| 71 | ProcessId pid() const { return pid_; } |
| 72 | ProcessId parent_pid() const { return ppid_; } |
| 73 | const char* exe_file() const { return exe_file_.c_str(); } |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 74 | }; |
| 75 | |
evanm@google.com | 0b100bc8 | 2008-10-14 20:49:16 | [diff] [blame] | 76 | struct IoCounters { |
evan@chromium.org | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 77 | uint64_t ReadOperationCount; |
| 78 | uint64_t WriteOperationCount; |
| 79 | uint64_t OtherOperationCount; |
| 80 | uint64_t ReadTransferCount; |
| 81 | uint64_t WriteTransferCount; |
| 82 | uint64_t OtherTransferCount; |
evanm@google.com | 0b100bc8 | 2008-10-14 20:49:16 | [diff] [blame] | 83 | }; |
agl@chromium.org | 3f04f2b | 2009-04-30 19:40:03 | [diff] [blame] | 84 | |
maruel@chromium.org | a5a00b1d | 2010-04-08 15:52:45 | [diff] [blame] | 85 | #endif // defined(OS_POSIX) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 86 | |
cpu@google.com | eef576f | 2008-11-03 23:28:06 | [diff] [blame] | 87 | // A minimalistic but hopefully cross-platform set of exit codes. |
| 88 | // Do not change the enumeration values or you will break third-party |
| 89 | // installers. |
| 90 | enum { |
thestig@chromium.org | e68639f5 | 2010-04-08 19:52:21 | [diff] [blame] | 91 | PROCESS_END_NORMAL_TERMINATION = 0, |
| 92 | PROCESS_END_KILLED_BY_USER = 1, |
| 93 | PROCESS_END_PROCESS_WAS_HUNG = 2 |
cpu@google.com | eef576f | 2008-11-03 23:28:06 | [diff] [blame] | 94 | }; |
| 95 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 96 | // Returns the id of the current process. |
phajdan.jr@chromium.org | 43cf325 | 2009-04-01 09:19:37 | [diff] [blame] | 97 | ProcessId GetCurrentProcId(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 98 | |
erikkay@google.com | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 99 | // Returns the ProcessHandle of the current process. |
| 100 | ProcessHandle GetCurrentProcessHandle(); |
maruel@chromium.org | 52a261f | 2009-03-03 15:01:12 | [diff] [blame] | 101 | |
brettw@google.com | 5986ed2 | 2009-02-06 00:19:17 | [diff] [blame] | 102 | // Converts a PID to a process handle. This handle must be closed by |
phajdan.jr@chromium.org | 6c6cc80 | 2009-04-03 17:01:36 | [diff] [blame] | 103 | // CloseProcessHandle when you are done with it. Returns true on success. |
| 104 | bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle); |
maruel@chromium.org | 52a261f | 2009-03-03 15:01:12 | [diff] [blame] | 105 | |
phajdan.jr@chromium.org | 5d438dbad | 2009-04-30 08:59:39 | [diff] [blame] | 106 | // Converts a PID to a process handle. On Windows the handle is opened |
| 107 | // with more access rights and must only be used by trusted code. |
| 108 | // You have to close returned handle using CloseProcessHandle. Returns true |
| 109 | // on success. |
| 110 | bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle); |
| 111 | |
brettw@google.com | 5986ed2 | 2009-02-06 00:19:17 | [diff] [blame] | 112 | // Closes the process handle opened by OpenProcessHandle. |
| 113 | void CloseProcessHandle(ProcessHandle process); |
erikkay@google.com | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 114 | |
cpu@google.com | eef576f | 2008-11-03 23:28:06 | [diff] [blame] | 115 | // Returns the unique ID for the specified process. This is functionally the |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 116 | // same as Windows' GetProcessId(), but works on versions of Windows before |
| 117 | // Win XP SP1 as well. |
phajdan.jr@chromium.org | 43cf325 | 2009-04-01 09:19:37 | [diff] [blame] | 118 | ProcessId GetProcId(ProcessHandle process); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 119 | |
dkegel@google.com | 78c6dd6 | 2009-06-08 23:29:11 | [diff] [blame] | 120 | #if defined(OS_LINUX) |
| 121 | // Returns the ID for the parent of the given process. |
| 122 | ProcessId GetParentProcessId(ProcessHandle process); |
| 123 | |
| 124 | // Returns the path to the executable of the given process. |
| 125 | FilePath GetProcessExecutablePath(ProcessHandle process); |
evan@chromium.org | d2ed2383 | 2009-09-19 01:57:39 | [diff] [blame] | 126 | |
| 127 | // Parse the data found in /proc/<pid>/stat and return the sum of the |
| 128 | // CPU-related ticks. Returns -1 on parse error. |
| 129 | // Exposed for testing. |
| 130 | int ParseProcStatCPU(const std::string& input); |
thestig@chromium.org | e5856a7a | 2009-12-10 02:08:10 | [diff] [blame] | 131 | |
| 132 | static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; |
| 133 | |
| 134 | // This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer |
| 135 | // certain process types over others. The range for the adjustment is |
| 136 | // [-17,15], with [0,15] being user accessible. |
| 137 | bool AdjustOOMScore(ProcessId process, int score); |
dkegel@google.com | 78c6dd6 | 2009-06-08 23:29:11 | [diff] [blame] | 138 | #endif |
| 139 | |
jeremy@chromium.org | fa3097a6a5 | 2008-12-17 22:41:50 | [diff] [blame] | 140 | #if defined(OS_POSIX) |
agl@chromium.org | 3f04f2b | 2009-04-30 19:40:03 | [diff] [blame] | 141 | // Close all file descriptors, expect those which are a destination in the |
| 142 | // given multimap. Only call this function in a child process where you know |
| 143 | // that there aren't any other threads. |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 144 | void CloseSuperfluousFds(const InjectiveMultimap& saved_map); |
jeremy@chromium.org | fa3097a6a5 | 2008-12-17 22:41:50 | [diff] [blame] | 145 | #endif |
| 146 | |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 147 | #if defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 148 | // Runs the given application name with the given command line. Normally, the |
| 149 | // first command line argument should be the path to the process, and don't |
| 150 | // forget to quote it. |
| 151 | // |
| 152 | // If wait is true, it will block and wait for the other process to finish, |
| 153 | // otherwise, it will just continue asynchronously. |
| 154 | // |
| 155 | // Example (including literal quotes) |
| 156 | // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\" |
| 157 | // |
| 158 | // If process_handle is non-NULL, the process handle of the launched app will be |
| 159 | // stored there on a successful launch. |
| 160 | // NOTE: In this case, the caller is responsible for closing the handle so |
| 161 | // that it doesn't leak! |
| 162 | bool LaunchApp(const std::wstring& cmdline, |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 163 | bool wait, bool start_hidden, ProcessHandle* process_handle); |
cpu@chromium.org | e50130b | 2010-02-01 03:28:47 | [diff] [blame] | 164 | |
| 165 | // Runs the given application name with the given command line as if the user |
| 166 | // represented by |token| had launched it. The caveats about |cmdline| and |
| 167 | // |process_handle| explained for LaunchApp above apply as well. |
| 168 | // |
| 169 | // Whether the application is visible on the interactive desktop depends on |
| 170 | // the token belonging to an interactive logon session. |
| 171 | // |
| 172 | // To avoid hard to diagnose problems, this function internally loads the |
| 173 | // environment variables associated with the user and if this operation fails |
| 174 | // the entire call fails as well. |
| 175 | bool LaunchAppAsUser(UserTokenHandle token, const std::wstring& cmdline, |
| 176 | bool start_hidden, ProcessHandle* process_handle); |
| 177 | |
gwilson@google.com | c020ddc | 2010-02-18 23:01:52 | [diff] [blame] | 178 | // Has the same behavior as LaunchAppAsUser, but offers the boolean option to |
| 179 | // use an empty string for the desktop name. |
| 180 | bool LaunchAppAsUser(UserTokenHandle token, const std::wstring& cmdline, |
| 181 | bool start_hidden, ProcessHandle* process_handle, |
| 182 | bool empty_desktop_name); |
| 183 | |
| 184 | |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 185 | #elif defined(OS_POSIX) |
| 186 | // Runs the application specified in argv[0] with the command line argv. |
jeremy@chromium.org | fa3097a6a5 | 2008-12-17 22:41:50 | [diff] [blame] | 187 | // Before launching all FDs open in the parent process will be marked as |
| 188 | // close-on-exec. |fds_to_remap| defines a mapping of src fd->dest fd to |
| 189 | // propagate FDs into the child process. |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 190 | // |
| 191 | // As above, if wait is true, execute synchronously. The pid will be stored |
| 192 | // in process_handle if that pointer is non-null. |
| 193 | // |
mattm@chromium.org | b74d21b3 | 2009-07-17 19:36:00 | [diff] [blame] | 194 | // Note that the first argument in argv must point to the executable filename. |
| 195 | // If the filename is not fully specified, PATH will be searched. |
jeremy@chromium.org | fa3097a6a5 | 2008-12-17 22:41:50 | [diff] [blame] | 196 | typedef std::vector<std::pair<int, int> > file_handle_mapping_vector; |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 197 | bool LaunchApp(const std::vector<std::string>& argv, |
jeremy@chromium.org | fa3097a6a5 | 2008-12-17 22:41:50 | [diff] [blame] | 198 | const file_handle_mapping_vector& fds_to_remap, |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 199 | bool wait, ProcessHandle* process_handle); |
stuartmorgan@google.com | 2aea9e09 | 2009-08-06 20:03:01 | [diff] [blame] | 200 | |
thakis@chromium.org | c002879 | 2010-01-12 00:39:15 | [diff] [blame] | 201 | // Similar to the above, but also (un)set environment variables in child process |
thestig@chromium.org | 9ec8db0 | 2009-07-21 07:00:13 | [diff] [blame] | 202 | // through |environ|. |
jam@chromium.org | 3d2217d | 2009-11-23 21:26:47 | [diff] [blame] | 203 | typedef std::vector<std::pair<std::string, std::string> > environment_vector; |
thestig@chromium.org | 9ec8db0 | 2009-07-21 07:00:13 | [diff] [blame] | 204 | bool LaunchApp(const std::vector<std::string>& argv, |
| 205 | const environment_vector& environ, |
| 206 | const file_handle_mapping_vector& fds_to_remap, |
| 207 | bool wait, ProcessHandle* process_handle); |
thakis@chromium.org | c002879 | 2010-01-12 00:39:15 | [diff] [blame] | 208 | |
agl@chromium.org | ef73044e | 2010-03-11 15:25:54 | [diff] [blame] | 209 | // AlterEnvironment returns a modified environment vector, constructed from the |
| 210 | // given environment and the list of changes given in |changes|. Each key in |
| 211 | // the environment is matched against the first element of the pairs. In the |
| 212 | // event of a match, the value is replaced by the second of the pair, unless |
| 213 | // the second is empty, in which case the key-value is removed. |
| 214 | // |
| 215 | // The returned array is allocated using new[] and must be freed by the caller. |
| 216 | char** AlterEnvironment(const environment_vector& changes, |
| 217 | const char* const* const env); |
| 218 | |
thakis@chromium.org | c002879 | 2010-01-12 00:39:15 | [diff] [blame] | 219 | #if defined(OS_MACOSX) |
| 220 | // Similar to the above, but also returns the new process's task_t if |
| 221 | // |task_handle| is not NULL. If |task_handle| is not NULL, the caller is |
| 222 | // responsible for calling |mach_port_deallocate()| on the returned handle. |
| 223 | bool LaunchAppAndGetTask(const std::vector<std::string>& argv, |
| 224 | const environment_vector& environ, |
| 225 | const file_handle_mapping_vector& fds_to_remap, |
| 226 | bool wait, |
| 227 | task_t* task_handle, |
| 228 | ProcessHandle* process_handle); |
| 229 | #endif // defined(OS_MACOSX) |
thestig@chromium.org | 9ec8db0 | 2009-07-21 07:00:13 | [diff] [blame] | 230 | #endif // defined(OS_POSIX) |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 231 | |
jcampan@chromium.org | 1e31211 | 2009-04-21 21:44:12 | [diff] [blame] | 232 | // Executes the application specified by cl. This function delegates to one |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 233 | // of the above two platform-specific functions. |
| 234 | bool LaunchApp(const CommandLine& cl, |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 235 | bool wait, bool start_hidden, ProcessHandle* process_handle); |
| 236 | |
jcampan@chromium.org | 1e31211 | 2009-04-21 21:44:12 | [diff] [blame] | 237 | // Executes the application specified by |cl| and wait for it to exit. Stores |
phajdan.jr@chromium.org | 1912cfe | 2009-04-21 08:09:30 | [diff] [blame] | 238 | // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true |
| 239 | // on success (application launched and exited cleanly, with exit code |
maruel@chromium.org | 96878a21 | 2010-06-10 18:26:33 | [diff] [blame] | 240 | // indicating success). |
phajdan.jr@chromium.org | c0b210ee | 2009-04-17 09:57:52 | [diff] [blame] | 241 | bool GetAppOutput(const CommandLine& cl, std::string* output); |
phajdan.jr@chromium.org | c0b210ee | 2009-04-17 09:57:52 | [diff] [blame] | 242 | |
viettrungluu@chromium.org | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 243 | #if defined(OS_POSIX) |
| 244 | // A restricted version of |GetAppOutput()| which (a) clears the environment, |
| 245 | // and (b) stores at most |max_output| bytes; also, it doesn't search the path |
| 246 | // for the command. |
| 247 | bool GetAppOutputRestricted(const CommandLine& cl, |
| 248 | std::string* output, size_t max_output); |
| 249 | #endif |
| 250 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 251 | // Used to filter processes by process ID. |
| 252 | class ProcessFilter { |
| 253 | public: |
| 254 | // Returns true to indicate set-inclusion and false otherwise. This method |
| 255 | // should not have side-effects and should be idempotent. |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 256 | virtual bool Includes(const ProcessEntry& entry) const = 0; |
ziadh@chromium.org | 695092f | 2010-08-02 16:34:16 | [diff] [blame^] | 257 | |
| 258 | protected: |
| 259 | virtual ~ProcessFilter() {} |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | // Returns the number of processes on the machine that are running from the |
| 263 | // given executable name. If filter is non-null, then only processes selected |
| 264 | // by the filter will be counted. |
| 265 | int GetProcessCount(const std::wstring& executable_name, |
| 266 | const ProcessFilter* filter); |
| 267 | |
| 268 | // Attempts to kill all the processes on the current machine that were launched |
| 269 | // from the given executable name, ending them with the given exit code. If |
| 270 | // filter is non-null, then only processes selected by the filter are killed. |
| 271 | // Returns false if all processes were able to be killed off, false if at least |
| 272 | // one couldn't be killed. |
| 273 | bool KillProcesses(const std::wstring& executable_name, int exit_code, |
| 274 | const ProcessFilter* filter); |
| 275 | |
| 276 | // Attempts to kill the process identified by the given process |
| 277 | // entry structure, giving it the specified exit code. If |wait| is true, wait |
| 278 | // for the process to be actually terminated before returning. |
| 279 | // Returns true if this is successful, false otherwise. |
stoyan@chromium.org | cd4fd15 | 2009-02-09 19:28:41 | [diff] [blame] | 280 | bool KillProcess(ProcessHandle process, int exit_code, bool wait); |
agl@chromium.org | dfe1486 | 2009-01-22 01:23:11 | [diff] [blame] | 281 | #if defined(OS_WIN) |
phajdan.jr@chromium.org | 43cf325 | 2009-04-01 09:19:37 | [diff] [blame] | 282 | bool KillProcessById(ProcessId process_id, int exit_code, bool wait); |
agl@chromium.org | dfe1486 | 2009-01-22 01:23:11 | [diff] [blame] | 283 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 284 | |
| 285 | // Get the termination status (exit code) of the process and return true if the |
agl@chromium.org | 140a7cd | 2009-04-28 01:37:23 | [diff] [blame] | 286 | // status indicates the process crashed. |child_exited| is set to true iff the |
| 287 | // child process has terminated. (|child_exited| may be NULL.) |
agl@chromium.org | 140a7cd | 2009-04-28 01:37:23 | [diff] [blame] | 288 | bool DidProcessCrash(bool* child_exited, ProcessHandle handle); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 289 | |
phajdan.jr@chromium.org | c785663 | 2009-01-13 17:38:49 | [diff] [blame] | 290 | // Waits for process to exit. In POSIX systems, if the process hasn't been |
| 291 | // signaled then puts the exit code in |exit_code|; otherwise it's considered |
| 292 | // a failure. On Windows |exit_code| is always filled. Returns true on success, |
| 293 | // and closes |handle| in any case. |
| 294 | bool WaitForExitCode(ProcessHandle handle, int* exit_code); |
| 295 | |
phajdan.jr@chromium.org | 8004e68 | 2010-03-16 07:41:22 | [diff] [blame] | 296 | // Waits for process to exit. If it did exit within |timeout_milliseconds|, |
| 297 | // then puts the exit code in |exit_code|, closes |handle|, and returns true. |
| 298 | // In POSIX systems, if the process has been signaled then |exit_code| is set |
| 299 | // to -1. Returns false on failure (the caller is then responsible for closing |
| 300 | // |handle|). |
| 301 | bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, |
| 302 | int64 timeout_milliseconds); |
| 303 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 304 | // Wait for all the processes based on the named executable to exit. If filter |
| 305 | // is non-null, then only processes selected by the filter are waited on. |
| 306 | // Returns after all processes have exited or wait_milliseconds have expired. |
| 307 | // Returns true if all the processes exited, false otherwise. |
| 308 | bool WaitForProcessesToExit(const std::wstring& executable_name, |
phajdan.jr@chromium.org | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 309 | int64 wait_milliseconds, |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 310 | const ProcessFilter* filter); |
| 311 | |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 312 | // Wait for a single process to exit. Return true if it exited cleanly within |
| 313 | // the given time limit. |
| 314 | bool WaitForSingleProcess(ProcessHandle handle, |
phajdan.jr@chromium.org | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 315 | int64 wait_milliseconds); |
estade@chromium.org | fb7f9be | 2008-10-22 01:15:47 | [diff] [blame] | 316 | |
phajdan.jr@chromium.org | 076bf0b6 | 2009-03-04 20:57:58 | [diff] [blame] | 317 | // Returns true when |wait_milliseconds| have elapsed and the process |
| 318 | // is still running. |
phajdan.jr@chromium.org | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 319 | bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds); |
phajdan.jr@chromium.org | 076bf0b6 | 2009-03-04 20:57:58 | [diff] [blame] | 320 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 321 | // Waits a certain amount of time (can be 0) for all the processes with a given |
| 322 | // executable name to exit, then kills off any of them that are still around. |
| 323 | // If filter is non-null, then only processes selected by the filter are waited |
| 324 | // on. Killed processes are ended with the given exit code. Returns false if |
| 325 | // any processes needed to be killed, true if they all exited cleanly within |
| 326 | // the wait_milliseconds delay. |
| 327 | bool CleanupProcesses(const std::wstring& executable_name, |
phajdan.jr@chromium.org | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 328 | int64 wait_milliseconds, |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 329 | int exit_code, |
| 330 | const ProcessFilter* filter); |
| 331 | |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 332 | // This class provides a way to iterate through a list of processes on the |
| 333 | // current machine with a specified filter. |
| 334 | // To use, create an instance and then call NextProcessEntry() until it returns |
| 335 | // false. |
| 336 | class ProcessIterator { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 337 | public: |
maruel@chromium.org | baead4f | 2010-06-11 19:10:30 | [diff] [blame] | 338 | typedef std::list<ProcessEntry> ProcessEntries; |
| 339 | |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 340 | explicit ProcessIterator(const ProcessFilter* filter); |
| 341 | virtual ~ProcessIterator(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 342 | |
| 343 | // If there's another process that matches the given executable name, |
| 344 | // returns a const pointer to the corresponding PROCESSENTRY32. |
| 345 | // If there are no more matching processes, returns NULL. |
| 346 | // The returned pointer will remain valid until NextProcessEntry() |
| 347 | // is called again or this NamedProcessIterator goes out of scope. |
| 348 | const ProcessEntry* NextProcessEntry(); |
| 349 | |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 350 | // Takes a snapshot of all the ProcessEntry found. |
maruel@chromium.org | baead4f | 2010-06-11 19:10:30 | [diff] [blame] | 351 | ProcessEntries Snapshot(); |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 352 | |
| 353 | protected: |
| 354 | virtual bool IncludeEntry(); |
| 355 | const ProcessEntry& entry() { return entry_; } |
| 356 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 357 | private: |
| 358 | // Determines whether there's another process (regardless of executable) |
| 359 | // left in the list of all processes. Returns true and sets entry_ to |
| 360 | // that process's info if there is one, false otherwise. |
| 361 | bool CheckForNextProcess(); |
| 362 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 363 | // Initializes a PROCESSENTRY32 data structure so that it's ready for |
| 364 | // use with Process32First/Process32Next. |
| 365 | void InitProcessEntry(ProcessEntry* entry); |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 366 | |
| 367 | #if defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 368 | HANDLE snapshot_; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 369 | bool started_iteration_; |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 370 | #elif defined(OS_MACOSX) |
mark@chromium.org | 962dd31 | 2009-02-05 21:44:13 | [diff] [blame] | 371 | std::vector<kinfo_proc> kinfo_procs_; |
| 372 | size_t index_of_kinfo_proc_; |
wtc@chromium.org | 4a34ce0 | 2009-08-31 22:25:00 | [diff] [blame] | 373 | #elif defined(OS_POSIX) |
| 374 | DIR *procfs_dir_; |
dkegel@google.com | ab0e222 | 2008-10-31 20:19:43 | [diff] [blame] | 375 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 376 | ProcessEntry entry_; |
| 377 | const ProcessFilter* filter_; |
| 378 | |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 379 | DISALLOW_COPY_AND_ASSIGN(ProcessIterator); |
| 380 | }; |
| 381 | |
| 382 | // This class provides a way to iterate through the list of processes |
| 383 | // on the current machine that were started from the given executable |
| 384 | // name. To use, create an instance and then call NextProcessEntry() |
| 385 | // until it returns false. |
| 386 | class NamedProcessIterator : public ProcessIterator { |
| 387 | public: |
| 388 | NamedProcessIterator(const std::wstring& executable_name, |
| 389 | const ProcessFilter* filter); |
| 390 | virtual ~NamedProcessIterator(); |
| 391 | |
| 392 | protected: |
| 393 | virtual bool IncludeEntry(); |
| 394 | |
| 395 | private: |
| 396 | std::wstring executable_name_; |
| 397 | |
| 398 | DISALLOW_COPY_AND_ASSIGN(NamedProcessIterator); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | // Working Set (resident) memory usage broken down by |
agl@chromium.org | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 402 | // |
| 403 | // On Windows: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 404 | // priv (private): These pages (kbytes) cannot be shared with any other process. |
| 405 | // shareable: These pages (kbytes) can be shared with other processes under |
| 406 | // the right circumstances. |
| 407 | // shared : These pages (kbytes) are currently shared with at least one |
| 408 | // other process. |
agl@chromium.org | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 409 | // |
| 410 | // On Linux: |
| 411 | // priv: Pages mapped only by this process |
| 412 | // shared: PSS or 0 if the kernel doesn't support this |
| 413 | // shareable: 0 |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 414 | // |
| 415 | // On OS X: TODO(thakis): Revise. |
| 416 | // priv: Memory. |
| 417 | // shared: 0 |
| 418 | // shareable: 0 |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 419 | struct WorkingSetKBytes { |
agl@chromium.org | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 420 | WorkingSetKBytes() : priv(0), shareable(0), shared(0) {} |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 421 | size_t priv; |
| 422 | size_t shareable; |
| 423 | size_t shared; |
| 424 | }; |
| 425 | |
| 426 | // Committed (resident + paged) memory usage broken down by |
| 427 | // private: These pages cannot be shared with any other process. |
| 428 | // mapped: These pages are mapped into the view of a section (backed by |
| 429 | // pagefile.sys) |
| 430 | // image: These pages are mapped into the view of an image section (backed by |
| 431 | // file system) |
| 432 | struct CommittedKBytes { |
agl@chromium.org | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 433 | CommittedKBytes() : priv(0), mapped(0), image(0) {} |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 434 | size_t priv; |
| 435 | size_t mapped; |
| 436 | size_t image; |
| 437 | }; |
| 438 | |
| 439 | // Free memory (Megabytes marked as free) in the 2G process address space. |
| 440 | // total : total amount in megabytes marked as free. Maximum value is 2048. |
| 441 | // largest : size of the largest contiguous amount of memory found. It is |
| 442 | // always smaller or equal to FreeMBytes::total. |
| 443 | // largest_ptr: starting address of the largest memory block. |
| 444 | struct FreeMBytes { |
| 445 | size_t total; |
| 446 | size_t largest; |
| 447 | void* largest_ptr; |
| 448 | }; |
| 449 | |
evan@chromium.org | d2ed2383 | 2009-09-19 01:57:39 | [diff] [blame] | 450 | // Convert a POSIX timeval to microseconds. |
| 451 | int64 TimeValToMicroseconds(const struct timeval& tv); |
| 452 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 453 | // Provides performance metrics for a specified process (CPU usage, memory and |
| 454 | // IO counters). To use it, invoke CreateProcessMetrics() to get an instance |
| 455 | // for a specific process, then access the information with the different get |
| 456 | // methods. |
| 457 | class ProcessMetrics { |
| 458 | public: |
| 459 | // Creates a ProcessMetrics for the specified process. |
| 460 | // The caller owns the returned object. |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 461 | #if !defined(OS_MACOSX) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 462 | static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 463 | #else |
| 464 | class PortProvider { |
| 465 | public: |
thakis@chromium.org | b2e8e08 | 2009-12-21 17:44:20 | [diff] [blame] | 466 | // Should return the mach task for |process| if possible, or else |
| 467 | // |MACH_PORT_NULL|. Only processes that this returns tasks for will have |
| 468 | // metrics on OS X (except for the current process, which always gets |
| 469 | // metrics). |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 470 | virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; |
| 471 | }; |
| 472 | |
| 473 | // The port provider needs to outlive the ProcessMetrics object returned by |
| 474 | // this function. If NULL is passed as provider, the returned object |
| 475 | // only returns valid metrics if |process| is the current process. |
| 476 | static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, |
| 477 | PortProvider* port_provider); |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 478 | #endif // !defined(OS_MACOSX) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 479 | |
| 480 | ~ProcessMetrics(); |
| 481 | |
| 482 | // Returns the current space allocated for the pagefile, in bytes (these pages |
thomasvl@chromium.org | 796da7c | 2009-06-11 12:45:45 | [diff] [blame] | 483 | // may or may not be in memory). On Linux, this returns the total virtual |
| 484 | // memory size. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 485 | size_t GetPagefileUsage() const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 486 | // Returns the peak space allocated for the pagefile, in bytes. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 487 | size_t GetPeakPagefileUsage() const; |
thomasvl@chromium.org | 796da7c | 2009-06-11 12:45:45 | [diff] [blame] | 488 | // Returns the current working set size, in bytes. On Linux, this returns |
| 489 | // the resident set size. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 490 | size_t GetWorkingSetSize() const; |
tc@google.com | 0c557f1 | 2009-05-11 23:35:52 | [diff] [blame] | 491 | // Returns the peak working set size, in bytes. |
| 492 | size_t GetPeakWorkingSetSize() const; |
erg@chromium.org | 98947a0 | 2010-05-11 17:46:08 | [diff] [blame] | 493 | // Returns private and sharedusage, in bytes. Private bytes is the amount of |
| 494 | // memory currently allocated to a process that cannot be shared. Returns |
| 495 | // false on platform specific error conditions. Note: |private_bytes| |
| 496 | // returns 0 on unsupported OSes: prior to XP SP2. |
| 497 | bool GetMemoryBytes(size_t* private_bytes, |
| 498 | size_t* shared_bytes); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 499 | // Fills a CommittedKBytes with both resident and paged |
| 500 | // memory usage as per definition of CommittedBytes. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 501 | void GetCommittedKBytes(CommittedKBytes* usage) const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 502 | // Fills a WorkingSetKBytes containing resident private and shared memory |
| 503 | // usage in bytes, as per definition of WorkingSetBytes. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 504 | bool GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 505 | |
| 506 | // Computes the current process available memory for allocation. |
| 507 | // It does a linear scan of the address space querying each memory region |
| 508 | // for its free (unallocated) status. It is useful for estimating the memory |
| 509 | // load and fragmentation. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 510 | bool CalculateFreeMemory(FreeMBytes* free) const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 511 | |
| 512 | // Returns the CPU usage in percent since the last time this method was |
| 513 | // called. The first time this method is called it returns 0 and will return |
| 514 | // the actual CPU info on subsequent calls. |
thakis@chromium.org | 022eab6 | 2010-01-13 04:55:06 | [diff] [blame] | 515 | // On Windows, the CPU usage value is for all CPUs. So if you have 2 CPUs and |
| 516 | // your process is using all the cycles of 1 CPU and not the other CPU, this |
| 517 | // method returns 50. |
| 518 | double GetCPUUsage(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 519 | |
| 520 | // Retrieves accounting information for all I/O operations performed by the |
| 521 | // process. |
| 522 | // If IO information is retrieved successfully, the function returns true |
| 523 | // and fills in the IO_COUNTERS passed in. The function returns false |
| 524 | // otherwise. |
phajdan.jr@chromium.org | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 525 | bool GetIOCounters(IoCounters* io_counters) const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 526 | |
| 527 | private: |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 528 | #if !defined(OS_MACOSX) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 529 | explicit ProcessMetrics(ProcessHandle process); |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 530 | #else |
| 531 | ProcessMetrics(ProcessHandle process, PortProvider* port_provider); |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 532 | #endif // !defined(OS_MACOSX) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 533 | |
| 534 | ProcessHandle process_; |
| 535 | |
| 536 | int processor_count_; |
| 537 | |
evan@chromium.org | d2ed2383 | 2009-09-19 01:57:39 | [diff] [blame] | 538 | // Used to store the previous times and CPU usage counts so we can |
| 539 | // compute the CPU usage between calls. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 540 | int64 last_time_; |
| 541 | int64 last_system_time_; |
| 542 | |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 543 | #if defined(OS_MACOSX) |
| 544 | // Queries the port provider if it's set. |
| 545 | mach_port_t TaskForPid(ProcessHandle process) const; |
| 546 | |
| 547 | PortProvider* port_provider_; |
pvalchev@google.com | 66700d4 | 2010-03-10 07:46:43 | [diff] [blame] | 548 | #elif defined(OS_POSIX) |
| 549 | // Jiffie count at the last_time_ we updated. |
| 550 | int last_cpu_; |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 551 | #endif // defined(OS_MACOSX) |
viettrungluu@chromium.org | 3740cb9b5 | 2009-12-19 04:50:04 | [diff] [blame] | 552 | |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 553 | DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 554 | }; |
| 555 | |
sgk@chromium.org | ed26d94 | 2009-11-09 06:57:28 | [diff] [blame] | 556 | // Returns the memory commited by the system in KBytes. |
| 557 | // Returns 0 if it can't compute the commit charge. |
| 558 | size_t GetSystemCommitCharge(); |
| 559 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 560 | // Enables low fragmentation heap (LFH) for every heaps of this process. This |
| 561 | // won't have any effect on heaps created after this function call. It will not |
| 562 | // modify data allocated in the heaps before calling this function. So it is |
| 563 | // better to call this function early in initialization and again before |
| 564 | // entering the main loop. |
| 565 | // Note: Returns true on Windows 2000 without doing anything. |
| 566 | bool EnableLowFragmentationHeap(); |
| 567 | |
maruel@chromium.org | d6fc9fd | 2009-10-27 18:03:47 | [diff] [blame] | 568 | // Enables 'terminate on heap corruption' flag. Helps protect against heap |
maruel@google.com | c9d4087 | 2008-09-24 12:58:37 | [diff] [blame] | 569 | // overflow. Has no effect if the OS doesn't provide the necessary facility. |
| 570 | void EnableTerminationOnHeapCorruption(); |
| 571 | |
avi@chromium.org | cccb2121 | 2009-11-12 20:39:56 | [diff] [blame] | 572 | #if !defined(OS_WIN) |
| 573 | // Turns on process termination if memory runs out. This is handled on Windows |
| 574 | // inside RegisterInvalidParamHandler(). |
| 575 | void EnableTerminationOnOutOfMemory(); |
avi@chromium.org | 6cfa339 | 2010-07-01 20:11:43 | [diff] [blame] | 576 | #if defined(OS_MACOSX) |
| 577 | // Exposed for testing. |
| 578 | malloc_zone_t* GetPurgeableZone(); |
| 579 | #endif |
avi@chromium.org | cccb2121 | 2009-11-12 20:39:56 | [diff] [blame] | 580 | #endif |
| 581 | |
maruel@chromium.org | d6fc9fd | 2009-10-27 18:03:47 | [diff] [blame] | 582 | #if defined(UNIT_TEST) |
| 583 | // Enables stack dump to console output on exception and signals. |
| 584 | // When enabled, the process will quit immediately. This is meant to be used in |
| 585 | // unit_tests only! |
| 586 | bool EnableInProcessStackDumping(); |
| 587 | #endif // defined(UNIT_TEST) |
| 588 | |
deanm@google.com | db71728 | 2008-08-27 13:48:03 | [diff] [blame] | 589 | // If supported on the platform, and the user has sufficent rights, increase |
| 590 | // the current process's scheduling priority to a high priority. |
| 591 | void RaiseProcessToHighPriority(); |
| 592 | |
mark@chromium.org | e9a8c19f | 2009-09-03 21:27:36 | [diff] [blame] | 593 | #if defined(OS_MACOSX) |
| 594 | // Restore the default exception handler, setting it to Apple Crash Reporter |
| 595 | // (ReportCrash). When forking and execing a new process, the child will |
| 596 | // inherit the parent's exception ports, which may be set to the Breakpad |
| 597 | // instance running inside the parent. The parent's Breakpad instance should |
| 598 | // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
| 599 | // in the child after forking will restore the standard exception handler. |
| 600 | // See http://crbug.com/20371/ for more details. |
| 601 | void RestoreDefaultExceptionHandler(); |
maruel@chromium.org | b6128aa | 2010-04-29 17:44:42 | [diff] [blame] | 602 | #endif // defined(OS_MACOSX) |
mark@chromium.org | e9a8c19f | 2009-09-03 21:27:36 | [diff] [blame] | 603 | |
brettw@google.com | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 604 | } // namespace base |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 605 | |
deanm@google.com | db71728 | 2008-08-27 13:48:03 | [diff] [blame] | 606 | #endif // BASE_PROCESS_UTIL_H_ |