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

Side by Side Diff: base/process_util.h

Issue 3386014: This adds some plumbing for propagating the status and error code of a (Closed)
Patch Set: Fixed Mac code to handle both SEGV and BUS Created 10 years, 3 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
« no previous file with comments | « no previous file | base/process_util_posix.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) 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 uint64_t OtherTransferCount; 82 uint64_t OtherTransferCount;
83 }; 83 };
84 84
85 #endif // defined(OS_POSIX) 85 #endif // defined(OS_POSIX)
86 86
87 // A minimalistic but hopefully cross-platform set of exit codes. 87 // A minimalistic but hopefully cross-platform set of exit codes.
88 // Do not change the enumeration values or you will break third-party 88 // Do not change the enumeration values or you will break third-party
89 // installers. 89 // installers.
90 enum { 90 enum {
91 PROCESS_END_NORMAL_TERMINATION = 0, 91 PROCESS_END_NORMAL_TERMINATION = 0,
92 PROCESS_END_KILLED_BY_USER = 1, 92 PROCESS_END_PROCESS_WAS_KILLED = 1,
93 PROCESS_END_PROCESS_WAS_HUNG = 2 93 PROCESS_END_PROCESS_WAS_HUNG = 2,
94 };
95
96 // Return status values from GetTerminationStatus
97 enum TerminationStatus {
98 TERMINATION_STATUS_NORMAL_TERMINATION = 0, // zero exit status
99 TERMINATION_STATUS_PROCESS_WAS_KILLED = 1, // e.g. SIGKILL or task manager
100 TERMINATION_STATUS_PROCESS_WAS_HUNG = 2,
101 TERMINATION_STATUS_PROCESS_CRASHED = 3, // e.g. Segmentation fault
102 TERMINATION_STATUS_ABNORMAL_TERMINATION = 4, // non-zero exit status
103 TERMINATION_STATUS_STILL_RUNNING = 5 // child hasn't exited yet
94 }; 104 };
95 105
96 // Returns the id of the current process. 106 // Returns the id of the current process.
97 ProcessId GetCurrentProcId(); 107 ProcessId GetCurrentProcId();
98 108
99 // Returns the ProcessHandle of the current process. 109 // Returns the ProcessHandle of the current process.
100 ProcessHandle GetCurrentProcessHandle(); 110 ProcessHandle GetCurrentProcessHandle();
101 111
102 // Converts a PID to a process handle. This handle must be closed by 112 // Converts a PID to a process handle. This handle must be closed by
103 // CloseProcessHandle when you are done with it. Returns true on success. 113 // CloseProcessHandle when you are done with it. Returns true on success.
(...skipping 27 matching lines...) Expand all
131 141
132 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; 142 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score";
133 143
134 // This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer 144 // 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 145 // certain process types over others. The range for the adjustment is
136 // [-17,15], with [0,15] being user accessible. 146 // [-17,15], with [0,15] being user accessible.
137 bool AdjustOOMScore(ProcessId process, int score); 147 bool AdjustOOMScore(ProcessId process, int score);
138 #endif 148 #endif
139 149
140 #if defined(OS_POSIX) 150 #if defined(OS_POSIX)
141 // Close all file descriptors, expect those which are a destination in the 151 // Close all file descriptors, except those which are a destination in the
142 // given multimap. Only call this function in a child process where you know 152 // given multimap. Only call this function in a child process where you know
143 // that there aren't any other threads. 153 // that there aren't any other threads.
144 void CloseSuperfluousFds(const InjectiveMultimap& saved_map); 154 void CloseSuperfluousFds(const InjectiveMultimap& saved_map);
145 #endif 155 #endif
146 156
147 #if defined(OS_WIN) 157 #if defined(OS_WIN)
148 158
149 enum IntegrityLevel { 159 enum IntegrityLevel {
150 INTEGRITY_UNKNOWN, 160 INTEGRITY_UNKNOWN,
151 LOW_INTEGRITY, 161 LOW_INTEGRITY,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 #if defined(OS_POSIX) 308 #if defined(OS_POSIX)
299 // Attempts to kill the process group identified by |process_group_id|. Returns 309 // Attempts to kill the process group identified by |process_group_id|. Returns
300 // true on success. 310 // true on success.
301 bool KillProcessGroup(ProcessHandle process_group_id); 311 bool KillProcessGroup(ProcessHandle process_group_id);
302 #endif 312 #endif
303 313
304 #if defined(OS_WIN) 314 #if defined(OS_WIN)
305 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); 315 bool KillProcessById(ProcessId process_id, int exit_code, bool wait);
306 #endif 316 #endif
307 317
308 // Get the termination status (exit code) of the process and return true if the 318 // Get the termination status (exit code) of the process and return an
309 // status indicates the process crashed. |child_exited| is set to true iff the 319 // appropriate interpretation of the result. |exit_code| is set to
310 // child process has terminated. (|child_exited| may be NULL.) 320 // the status returned by waitpid() on Posix, and from
311 bool DidProcessCrash(bool* child_exited, ProcessHandle handle); 321 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the
322 // caller is not interested in it.
323 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code);
312 324
313 // Waits for process to exit. In POSIX systems, if the process hasn't been 325 // Waits for process to exit. In POSIX systems, if the process hasn't been
314 // signaled then puts the exit code in |exit_code|; otherwise it's considered 326 // signaled then puts the exit code in |exit_code|; otherwise it's considered
315 // a failure. On Windows |exit_code| is always filled. Returns true on success, 327 // a failure. On Windows |exit_code| is always filled. Returns true on success,
316 // and closes |handle| in any case. 328 // and closes |handle| in any case.
317 bool WaitForExitCode(ProcessHandle handle, int* exit_code); 329 bool WaitForExitCode(ProcessHandle handle, int* exit_code);
318 330
319 // Waits for process to exit. If it did exit within |timeout_milliseconds|, 331 // Waits for process to exit. If it did exit within |timeout_milliseconds|,
320 // then puts the exit code in |exit_code|, closes |handle|, and returns true. 332 // then puts the exit code in |exit_code|, closes |handle|, and returns true.
321 // In POSIX systems, if the process has been signaled then |exit_code| is set 333 // 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
620 // instance running inside the parent. The parent's Breakpad instance should 632 // instance running inside the parent. The parent's Breakpad instance should
621 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler 633 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler
622 // in the child after forking will restore the standard exception handler. 634 // in the child after forking will restore the standard exception handler.
623 // See http://crbug.com/20371/ for more details. 635 // See http://crbug.com/20371/ for more details.
624 void RestoreDefaultExceptionHandler(); 636 void RestoreDefaultExceptionHandler();
625 #endif // defined(OS_MACOSX) 637 #endif // defined(OS_MACOSX)
626 638
627 } // namespace base 639 } // namespace base
628 640
629 #endif // BASE_PROCESS_UTIL_H_ 641 #endif // BASE_PROCESS_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698