Chromium Code Reviews| 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 // A minimalistic but hopefully cross-platform set of exit codes. Do |
| 122 // Do not change the enumeration values or you will break third-party | 122 // not change the enumeration values or you will break third-party |
| 123 // installers. | 123 // installers. You may use these as arguments for KillProcess*() |
| 124 enum { | 124 // (among other uses). |
| 125 PROCESS_END_NORMAL_TERMINATION = 0, | 125 enum ExitCode { |
|
brettw
2010/12/03 01:01:54
I'm kind of sad to see this enumeration here (I re
Greg Spencer (Chromium)
2010/12/03 18:29:25
Yeah, I'm not a big fan of this enum either, but t
brettw
2010/12/09 16:48:49
I don't really like the exit codes here, personall
brettw
2010/12/09 17:22:13
I'm more sure that I don't want this in base.
The
Greg Spencer (Chromium)
2010/12/09 17:58:42
OK, as I said, I'm happy taking the exit code out
| |
| 126 PROCESS_END_KILLED_BY_USER = 1, | 126 EXIT_CODE_NORMAL_TERMINATION = 0, |
| 127 PROCESS_END_PROCESS_WAS_HUNG = 2 | 127 EXIT_CODE_PROCESS_WAS_KILLED = 1, |
| 128 EXIT_CODE_PROCESS_WAS_HUNG = 2, | |
| 129 }; | |
| 130 | |
| 131 // Return status values from GetTerminationStatus. Don't use these as | |
| 132 // arguments to KillProcess*(), use ExitCode values above instead. | |
| 133 enum TerminationStatus { | |
| 134 TERMINATION_STATUS_NORMAL_TERMINATION = 0, // zero exit status | |
| 135 TERMINATION_STATUS_PROCESS_WAS_KILLED = 1, // e.g. SIGKILL or task manager | |
| 136 TERMINATION_STATUS_PROCESS_WAS_HUNG = 2, | |
| 137 TERMINATION_STATUS_PROCESS_CRASHED = 3, // e.g. Segmentation fault | |
| 138 TERMINATION_STATUS_ABNORMAL_TERMINATION = 4, // non-zero exit status | |
| 139 TERMINATION_STATUS_STILL_RUNNING = 5 // child hasn't exited yet | |
| 128 }; | 140 }; |
| 129 | 141 |
| 130 // Returns the id of the current process. | 142 // Returns the id of the current process. |
| 131 ProcessId GetCurrentProcId(); | 143 ProcessId GetCurrentProcId(); |
| 132 | 144 |
| 133 // Returns the ProcessHandle of the current process. | 145 // Returns the ProcessHandle of the current process. |
| 134 ProcessHandle GetCurrentProcessHandle(); | 146 ProcessHandle GetCurrentProcessHandle(); |
| 135 | 147 |
| 136 // Converts a PID to a process handle. This handle must be closed by | 148 // 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. | 149 // 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 | 185 |
| 174 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; | 186 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; |
| 175 | 187 |
| 176 // This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer | 188 // 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 | 189 // certain process types over others. The range for the adjustment is |
| 178 // [-17,15], with [0,15] being user accessible. | 190 // [-17,15], with [0,15] being user accessible. |
| 179 bool AdjustOOMScore(ProcessId process, int score); | 191 bool AdjustOOMScore(ProcessId process, int score); |
| 180 #endif | 192 #endif |
| 181 | 193 |
| 182 #if defined(OS_POSIX) | 194 #if defined(OS_POSIX) |
| 183 // Close all file descriptors, expect those which are a destination in the | 195 // 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 | 196 // given multimap. Only call this function in a child process where you know |
| 185 // that there aren't any other threads. | 197 // that there aren't any other threads. |
| 186 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); | 198 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); |
| 187 #endif | 199 #endif |
| 188 | 200 |
| 189 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
| 190 | 202 |
| 191 enum IntegrityLevel { | 203 enum IntegrityLevel { |
| 192 INTEGRITY_UNKNOWN, | 204 INTEGRITY_UNKNOWN, |
| 193 LOW_INTEGRITY, | 205 LOW_INTEGRITY, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 #if defined(OS_POSIX) | 352 #if defined(OS_POSIX) |
| 341 // Attempts to kill the process group identified by |process_group_id|. Returns | 353 // Attempts to kill the process group identified by |process_group_id|. Returns |
| 342 // true on success. | 354 // true on success. |
| 343 bool KillProcessGroup(ProcessHandle process_group_id); | 355 bool KillProcessGroup(ProcessHandle process_group_id); |
| 344 #endif | 356 #endif |
| 345 | 357 |
| 346 #if defined(OS_WIN) | 358 #if defined(OS_WIN) |
| 347 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); | 359 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); |
| 348 #endif | 360 #endif |
| 349 | 361 |
| 350 // Get the termination status (exit code) of the process and return true if the | 362 // Get the termination status of the process by interpreting the |
| 351 // status indicates the process crashed. |child_exited| is set to true iff the | 363 // circumstances of the child process' death. |exit_code| is set to |
| 352 // child process has terminated. (|child_exited| may be NULL.) | 364 // the status returned by waitpid() on POSIX, and from |
| 353 bool DidProcessCrash(bool* child_exited, ProcessHandle handle); | 365 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the |
| 366 // caller is not interested in it. | |
| 367 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code); | |
| 354 | 368 |
| 355 // Waits for process to exit. In POSIX systems, if the process hasn't been | 369 // 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 | 370 // 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, | 371 // a failure. On Windows |exit_code| is always filled. Returns true on success, |
| 358 // and closes |handle| in any case. | 372 // and closes |handle| in any case. |
| 359 bool WaitForExitCode(ProcessHandle handle, int* exit_code); | 373 bool WaitForExitCode(ProcessHandle handle, int* exit_code); |
| 360 | 374 |
| 361 // Waits for process to exit. If it did exit within |timeout_milliseconds|, | 375 // 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. | 376 // 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 | 377 // 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 | 676 // instance running inside the parent. The parent's Breakpad instance should |
| 663 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 677 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
| 664 // in the child after forking will restore the standard exception handler. | 678 // in the child after forking will restore the standard exception handler. |
| 665 // See http://crbug.com/20371/ for more details. | 679 // See http://crbug.com/20371/ for more details. |
| 666 void RestoreDefaultExceptionHandler(); | 680 void RestoreDefaultExceptionHandler(); |
| 667 #endif // defined(OS_MACOSX) | 681 #endif // defined(OS_MACOSX) |
| 668 | 682 |
| 669 } // namespace base | 683 } // namespace base |
| 670 | 684 |
| 671 #endif // BASE_PROCESS_UTIL_H_ | 685 #endif // BASE_PROCESS_UTIL_H_ |
| OLD | NEW |