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

Side by Side Diff: base/process_util.h

Issue 57062: Use portable typedef for PIDs (process IDs). (Closed)
Patch Set: speculative fix for win Created 11 years, 8 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 | « base/process_posix.cc ('k') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // A minimalistic but hopefully cross-platform set of exit codes. 55 // A minimalistic but hopefully cross-platform set of exit codes.
56 // Do not change the enumeration values or you will break third-party 56 // Do not change the enumeration values or you will break third-party
57 // installers. 57 // installers.
58 enum { 58 enum {
59 PROCESS_END_NORMAL_TERMINATON = 0, 59 PROCESS_END_NORMAL_TERMINATON = 0,
60 PROCESS_END_KILLED_BY_USER = 1, 60 PROCESS_END_KILLED_BY_USER = 1,
61 PROCESS_END_PROCESS_WAS_HUNG = 2 61 PROCESS_END_PROCESS_WAS_HUNG = 2
62 }; 62 };
63 63
64 // Returns the id of the current process. 64 // Returns the id of the current process.
65 int GetCurrentProcId(); 65 ProcessId GetCurrentProcId();
66 66
67 // Returns the ProcessHandle of the current process. 67 // Returns the ProcessHandle of the current process.
68 ProcessHandle GetCurrentProcessHandle(); 68 ProcessHandle GetCurrentProcessHandle();
69 69
70 // Converts a PID to a process handle. This handle must be closed by 70 // Converts a PID to a process handle. This handle must be closed by
71 // CloseProcessHandle when you are done with it. 71 // CloseProcessHandle when you are done with it.
72 ProcessHandle OpenProcessHandle(int pid); 72 ProcessHandle OpenProcessHandle(ProcessId pid);
73 73
74 // Closes the process handle opened by OpenProcessHandle. 74 // Closes the process handle opened by OpenProcessHandle.
75 void CloseProcessHandle(ProcessHandle process); 75 void CloseProcessHandle(ProcessHandle process);
76 76
77 // Returns the unique ID for the specified process. This is functionally the 77 // Returns the unique ID for the specified process. This is functionally the
78 // same as Windows' GetProcessId(), but works on versions of Windows before 78 // same as Windows' GetProcessId(), but works on versions of Windows before
79 // Win XP SP1 as well. 79 // Win XP SP1 as well.
80 int GetProcId(ProcessHandle process); 80 ProcessId GetProcId(ProcessHandle process);
81 81
82 #if defined(OS_POSIX) 82 #if defined(OS_POSIX)
83 // Sets all file descriptors to close on exec except for stdin, stdout 83 // Sets all file descriptors to close on exec except for stdin, stdout
84 // and stderr. 84 // and stderr.
85 void SetAllFDsToCloseOnExec(); 85 void SetAllFDsToCloseOnExec();
86 #endif 86 #endif
87 87
88 #if defined(OS_WIN) 88 #if defined(OS_WIN)
89 // Runs the given application name with the given command line. Normally, the 89 // Runs the given application name with the given command line. Normally, the
90 // first command line argument should be the path to the process, and don't 90 // first command line argument should be the path to the process, and don't
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Execute the application specified by cl. This function delegates to one 122 // Execute the application specified by cl. This function delegates to one
123 // of the above two platform-specific functions. 123 // of the above two platform-specific functions.
124 bool LaunchApp(const CommandLine& cl, 124 bool LaunchApp(const CommandLine& cl,
125 bool wait, bool start_hidden, ProcessHandle* process_handle); 125 bool wait, bool start_hidden, ProcessHandle* process_handle);
126 126
127 // Used to filter processes by process ID. 127 // Used to filter processes by process ID.
128 class ProcessFilter { 128 class ProcessFilter {
129 public: 129 public:
130 // Returns true to indicate set-inclusion and false otherwise. This method 130 // Returns true to indicate set-inclusion and false otherwise. This method
131 // should not have side-effects and should be idempotent. 131 // should not have side-effects and should be idempotent.
132 virtual bool Includes(uint32 pid, uint32 parent_pid) const = 0; 132 virtual bool Includes(ProcessId pid, ProcessId parent_pid) const = 0;
133 virtual ~ProcessFilter() { } 133 virtual ~ProcessFilter() { }
134 }; 134 };
135 135
136 // Returns the number of processes on the machine that are running from the 136 // Returns the number of processes on the machine that are running from the
137 // given executable name. If filter is non-null, then only processes selected 137 // given executable name. If filter is non-null, then only processes selected
138 // by the filter will be counted. 138 // by the filter will be counted.
139 int GetProcessCount(const std::wstring& executable_name, 139 int GetProcessCount(const std::wstring& executable_name,
140 const ProcessFilter* filter); 140 const ProcessFilter* filter);
141 141
142 // Attempts to kill all the processes on the current machine that were launched 142 // Attempts to kill all the processes on the current machine that were launched
143 // from the given executable name, ending them with the given exit code. If 143 // from the given executable name, ending them with the given exit code. If
144 // filter is non-null, then only processes selected by the filter are killed. 144 // filter is non-null, then only processes selected by the filter are killed.
145 // Returns false if all processes were able to be killed off, false if at least 145 // Returns false if all processes were able to be killed off, false if at least
146 // one couldn't be killed. 146 // one couldn't be killed.
147 bool KillProcesses(const std::wstring& executable_name, int exit_code, 147 bool KillProcesses(const std::wstring& executable_name, int exit_code,
148 const ProcessFilter* filter); 148 const ProcessFilter* filter);
149 149
150 // Attempts to kill the process identified by the given process 150 // Attempts to kill the process identified by the given process
151 // entry structure, giving it the specified exit code. If |wait| is true, wait 151 // entry structure, giving it the specified exit code. If |wait| is true, wait
152 // for the process to be actually terminated before returning. 152 // for the process to be actually terminated before returning.
153 // Returns true if this is successful, false otherwise. 153 // Returns true if this is successful, false otherwise.
154 bool KillProcess(ProcessHandle process, int exit_code, bool wait); 154 bool KillProcess(ProcessHandle process, int exit_code, bool wait);
155 #if defined(OS_WIN) 155 #if defined(OS_WIN)
156 bool KillProcessById(DWORD process_id, int exit_code, bool wait); 156 bool KillProcessById(ProcessId process_id, int exit_code, bool wait);
157 #endif 157 #endif
158 158
159 // Get the termination status (exit code) of the process and return true if the 159 // Get the termination status (exit code) of the process and return true if the
160 // status indicates the process crashed. It is an error to call this if the 160 // status indicates the process crashed. It is an error to call this if the
161 // process hasn't terminated yet. 161 // process hasn't terminated yet.
162 bool DidProcessCrash(ProcessHandle handle); 162 bool DidProcessCrash(ProcessHandle handle);
163 163
164 // Waits for process to exit. In POSIX systems, if the process hasn't been 164 // Waits for process to exit. In POSIX systems, if the process hasn't been
165 // signaled then puts the exit code in |exit_code|; otherwise it's considered 165 // signaled then puts the exit code in |exit_code|; otherwise it's considered
166 // a failure. On Windows |exit_code| is always filled. Returns true on success, 166 // a failure. On Windows |exit_code| is always filled. Returns true on success,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // overflow. Has no effect if the OS doesn't provide the necessary facility. 353 // overflow. Has no effect if the OS doesn't provide the necessary facility.
354 void EnableTerminationOnHeapCorruption(); 354 void EnableTerminationOnHeapCorruption();
355 355
356 // If supported on the platform, and the user has sufficent rights, increase 356 // If supported on the platform, and the user has sufficent rights, increase
357 // the current process's scheduling priority to a high priority. 357 // the current process's scheduling priority to a high priority.
358 void RaiseProcessToHighPriority(); 358 void RaiseProcessToHighPriority();
359 359
360 } // namespace base 360 } // namespace base
361 361
362 #endif // BASE_PROCESS_UTIL_H_ 362 #endif // BASE_PROCESS_UTIL_H_
OLDNEW
« no previous file with comments | « base/process_posix.cc ('k') | base/process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698