OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file/namespace contains utility functions for enumerating, ending and | 5 // This file/namespace contains utility functions for enumerating, ending and |
6 // computing statistics of processes. | 6 // computing statistics of processes. |
7 | 7 |
8 #ifndef BASE_PROCESS_UTIL_H_ | 8 #ifndef BASE_PROCESS_UTIL_H_ |
9 #define BASE_PROCESS_UTIL_H_ | 9 #define BASE_PROCESS_UTIL_H_ |
10 #pragma once | 10 #pragma once |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 const uint32 kProcessAccessSuspendResume = 0; | 116 const uint32 kProcessAccessSuspendResume = 0; |
117 const uint32 kProcessAccessQueryLimitedInfomation = 0; | 117 const uint32 kProcessAccessQueryLimitedInfomation = 0; |
118 const uint32 kProcessAccessWaitForTermination = 0; | 118 const uint32 kProcessAccessWaitForTermination = 0; |
119 #endif // defined(OS_POSIX) | 119 #endif // defined(OS_POSIX) |
120 | 120 |
121 // A minimalistic but hopefully cross-platform set of exit codes. | 121 // A minimalistic but hopefully cross-platform set of exit codes. |
122 // Do not change the enumeration values or you will break third-party | 122 // Do not change the enumeration values or you will break third-party |
123 // installers. | 123 // installers. |
124 enum { | 124 enum { |
125 PROCESS_END_NORMAL_TERMINATION = 0, | 125 PROCESS_END_NORMAL_TERMINATION = 0, |
126 PROCESS_END_KILLED_BY_USER = 1, | 126 PROCESS_END_PROCESS_WAS_KILLED = 1, |
127 PROCESS_END_PROCESS_WAS_HUNG = 2 | 127 PROCESS_END_PROCESS_WAS_HUNG = 2, |
| 128 }; |
| 129 |
| 130 // Return status values from GetTerminationStatus |
| 131 enum TerminationStatus { |
| 132 TERMINATION_STATUS_NORMAL_TERMINATION = 0, // zero exit status |
| 133 TERMINATION_STATUS_PROCESS_WAS_KILLED = 1, // e.g. SIGKILL or task manager |
| 134 TERMINATION_STATUS_PROCESS_WAS_HUNG = 2, |
| 135 TERMINATION_STATUS_PROCESS_CRASHED = 3, // e.g. Segmentation fault |
| 136 TERMINATION_STATUS_ABNORMAL_TERMINATION = 4, // non-zero exit status |
| 137 TERMINATION_STATUS_STILL_RUNNING = 5 // child hasn't exited yet |
128 }; | 138 }; |
129 | 139 |
130 // Returns the id of the current process. | 140 // Returns the id of the current process. |
131 ProcessId GetCurrentProcId(); | 141 ProcessId GetCurrentProcId(); |
132 | 142 |
133 // Returns the ProcessHandle of the current process. | 143 // Returns the ProcessHandle of the current process. |
134 ProcessHandle GetCurrentProcessHandle(); | 144 ProcessHandle GetCurrentProcessHandle(); |
135 | 145 |
136 // Converts a PID to a process handle. This handle must be closed by | 146 // Converts a PID to a process handle. This handle must be closed by |
137 // CloseProcessHandle when you are done with it. Returns true on success. | 147 // CloseProcessHandle when you are done with it. Returns true on success. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 183 |
174 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; | 184 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; |
175 | 185 |
176 // This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer | 186 // This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer |
177 // certain process types over others. The range for the adjustment is | 187 // certain process types over others. The range for the adjustment is |
178 // [-17,15], with [0,15] being user accessible. | 188 // [-17,15], with [0,15] being user accessible. |
179 bool AdjustOOMScore(ProcessId process, int score); | 189 bool AdjustOOMScore(ProcessId process, int score); |
180 #endif | 190 #endif |
181 | 191 |
182 #if defined(OS_POSIX) | 192 #if defined(OS_POSIX) |
183 // Close all file descriptors, expect those which are a destination in the | 193 // Close all file descriptors, except those which are a destination in the |
184 // given multimap. Only call this function in a child process where you know | 194 // given multimap. Only call this function in a child process where you know |
185 // that there aren't any other threads. | 195 // that there aren't any other threads. |
186 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); | 196 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); |
187 #endif | 197 #endif |
188 | 198 |
189 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
190 | 200 |
191 enum IntegrityLevel { | 201 enum IntegrityLevel { |
192 INTEGRITY_UNKNOWN, | 202 INTEGRITY_UNKNOWN, |
193 LOW_INTEGRITY, | 203 LOW_INTEGRITY, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 #if defined(OS_POSIX) | 350 #if defined(OS_POSIX) |
341 // Attempts to kill the process group identified by |process_group_id|. Returns | 351 // Attempts to kill the process group identified by |process_group_id|. Returns |
342 // true on success. | 352 // true on success. |
343 bool KillProcessGroup(ProcessHandle process_group_id); | 353 bool KillProcessGroup(ProcessHandle process_group_id); |
344 #endif | 354 #endif |
345 | 355 |
346 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
347 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); | 357 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); |
348 #endif | 358 #endif |
349 | 359 |
350 // Get the termination status (exit code) of the process and return true if the | 360 // Get the termination status (exit code) of the process and return an |
351 // status indicates the process crashed. |child_exited| is set to true iff the | 361 // appropriate interpretation of the result. |exit_code| is set to |
352 // child process has terminated. (|child_exited| may be NULL.) | 362 // the status returned by waitpid() on Posix, and from |
353 bool DidProcessCrash(bool* child_exited, ProcessHandle handle); | 363 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the |
| 364 // caller is not interested in it. |
| 365 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code); |
354 | 366 |
355 // Waits for process to exit. In POSIX systems, if the process hasn't been | 367 // Waits for process to exit. In POSIX systems, if the process hasn't been |
356 // signaled then puts the exit code in |exit_code|; otherwise it's considered | 368 // signaled then puts the exit code in |exit_code|; otherwise it's considered |
357 // a failure. On Windows |exit_code| is always filled. Returns true on success, | 369 // a failure. On Windows |exit_code| is always filled. Returns true on success, |
358 // and closes |handle| in any case. | 370 // and closes |handle| in any case. |
359 bool WaitForExitCode(ProcessHandle handle, int* exit_code); | 371 bool WaitForExitCode(ProcessHandle handle, int* exit_code); |
360 | 372 |
361 // Waits for process to exit. If it did exit within |timeout_milliseconds|, | 373 // Waits for process to exit. If it did exit within |timeout_milliseconds|, |
362 // then puts the exit code in |exit_code|, closes |handle|, and returns true. | 374 // then puts the exit code in |exit_code|, closes |handle|, and returns true. |
363 // In POSIX systems, if the process has been signaled then |exit_code| is set | 375 // In POSIX systems, if the process has been signaled then |exit_code| is set |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 // instance running inside the parent. The parent's Breakpad instance should | 674 // instance running inside the parent. The parent's Breakpad instance should |
663 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 675 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
664 // in the child after forking will restore the standard exception handler. | 676 // in the child after forking will restore the standard exception handler. |
665 // See http://crbug.com/20371/ for more details. | 677 // See http://crbug.com/20371/ for more details. |
666 void RestoreDefaultExceptionHandler(); | 678 void RestoreDefaultExceptionHandler(); |
667 #endif // defined(OS_MACOSX) | 679 #endif // defined(OS_MACOSX) |
668 | 680 |
669 } // namespace base | 681 } // namespace base |
670 | 682 |
671 #endif // BASE_PROCESS_UTIL_H_ | 683 #endif // BASE_PROCESS_UTIL_H_ |
OLD | NEW |