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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const uint32 kProcessAccessDuplicateHandle = 0; | 111 const uint32 kProcessAccessDuplicateHandle = 0; |
112 const uint32 kProcessAccessCreateProcess = 0; | 112 const uint32 kProcessAccessCreateProcess = 0; |
113 const uint32 kProcessAccessSetQuota = 0; | 113 const uint32 kProcessAccessSetQuota = 0; |
114 const uint32 kProcessAccessSetInformation = 0; | 114 const uint32 kProcessAccessSetInformation = 0; |
115 const uint32 kProcessAccessQueryInformation = 0; | 115 const uint32 kProcessAccessQueryInformation = 0; |
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 // Return status values from GetTerminationStatus. Don't use these as |
122 // Do not change the enumeration values or you will break third-party | 122 // exit code arguments to KillProcess*(), use platform/application |
123 // installers. | 123 // specific values instead. |
124 enum { | 124 enum TerminationStatus { |
125 PROCESS_END_NORMAL_TERMINATION = 0, | 125 TERMINATION_STATUS_NORMAL_TERMINATION, // zero exit status |
126 PROCESS_END_KILLED_BY_USER = 1, | 126 TERMINATION_STATUS_ABNORMAL_TERMINATION, // non-zero exit status |
127 PROCESS_END_PROCESS_WAS_HUNG = 2 | 127 TERMINATION_STATUS_PROCESS_WAS_KILLED, // e.g. SIGKILL or task manager kill |
| 128 TERMINATION_STATUS_PROCESS_CRASHED, // e.g. Segmentation fault |
| 129 TERMINATION_STATUS_STILL_RUNNING // child hasn't exited yet |
128 }; | 130 }; |
129 | 131 |
130 // Returns the id of the current process. | 132 // Returns the id of the current process. |
131 ProcessId GetCurrentProcId(); | 133 ProcessId GetCurrentProcId(); |
132 | 134 |
133 // Returns the ProcessHandle of the current process. | 135 // Returns the ProcessHandle of the current process. |
134 ProcessHandle GetCurrentProcessHandle(); | 136 ProcessHandle GetCurrentProcessHandle(); |
135 | 137 |
136 // Converts a PID to a process handle. This handle must be closed by | 138 // 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. | 139 // 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 | 175 |
174 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; | 176 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; |
175 | 177 |
176 // This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer | 178 // 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 | 179 // certain process types over others. The range for the adjustment is |
178 // [-17,15], with [0,15] being user accessible. | 180 // [-17,15], with [0,15] being user accessible. |
179 bool AdjustOOMScore(ProcessId process, int score); | 181 bool AdjustOOMScore(ProcessId process, int score); |
180 #endif | 182 #endif |
181 | 183 |
182 #if defined(OS_POSIX) | 184 #if defined(OS_POSIX) |
183 // Close all file descriptors, expect those which are a destination in the | 185 // 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 | 186 // given multimap. Only call this function in a child process where you know |
185 // that there aren't any other threads. | 187 // that there aren't any other threads. |
186 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); | 188 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); |
187 #endif | 189 #endif |
188 | 190 |
189 #if defined(OS_WIN) | 191 #if defined(OS_WIN) |
190 | 192 |
191 enum IntegrityLevel { | 193 enum IntegrityLevel { |
192 INTEGRITY_UNKNOWN, | 194 INTEGRITY_UNKNOWN, |
193 LOW_INTEGRITY, | 195 LOW_INTEGRITY, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 #if defined(OS_POSIX) | 342 #if defined(OS_POSIX) |
341 // Attempts to kill the process group identified by |process_group_id|. Returns | 343 // Attempts to kill the process group identified by |process_group_id|. Returns |
342 // true on success. | 344 // true on success. |
343 bool KillProcessGroup(ProcessHandle process_group_id); | 345 bool KillProcessGroup(ProcessHandle process_group_id); |
344 #endif | 346 #endif |
345 | 347 |
346 #if defined(OS_WIN) | 348 #if defined(OS_WIN) |
347 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); | 349 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); |
348 #endif | 350 #endif |
349 | 351 |
350 // Get the termination status (exit code) of the process and return true if the | 352 // Get the termination status of the process by interpreting the |
351 // status indicates the process crashed. |child_exited| is set to true iff the | 353 // circumstances of the child process' death. |exit_code| is set to |
352 // child process has terminated. (|child_exited| may be NULL.) | 354 // the status returned by waitpid() on POSIX, and from |
353 bool DidProcessCrash(bool* child_exited, ProcessHandle handle); | 355 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the |
| 356 // caller is not interested in it. Note that on Linux, this function |
| 357 // will only return a useful result the first time it is called after |
| 358 // the child exits (because it will reap the child and the information |
| 359 // will no longer be available). |
| 360 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code); |
354 | 361 |
355 // Waits for process to exit. In POSIX systems, if the process hasn't been | 362 // 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 | 363 // 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, | 364 // a failure. On Windows |exit_code| is always filled. Returns true on success, |
358 // and closes |handle| in any case. | 365 // and closes |handle| in any case. |
359 bool WaitForExitCode(ProcessHandle handle, int* exit_code); | 366 bool WaitForExitCode(ProcessHandle handle, int* exit_code); |
360 | 367 |
361 // Waits for process to exit. If it did exit within |timeout_milliseconds|, | 368 // 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. | 369 // 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 | 370 // 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 | 669 // instance running inside the parent. The parent's Breakpad instance should |
663 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 670 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
664 // in the child after forking will restore the standard exception handler. | 671 // in the child after forking will restore the standard exception handler. |
665 // See http://crbug.com/20371/ for more details. | 672 // See http://crbug.com/20371/ for more details. |
666 void RestoreDefaultExceptionHandler(); | 673 void RestoreDefaultExceptionHandler(); |
667 #endif // defined(OS_MACOSX) | 674 #endif // defined(OS_MACOSX) |
668 | 675 |
669 } // namespace base | 676 } // namespace base |
670 | 677 |
671 #endif // BASE_PROCESS_UTIL_H_ | 678 #endif // BASE_PROCESS_UTIL_H_ |
OLD | NEW |