|
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 |
|
3 // found in the LICENSE file. |
|
4 |
|
5 #ifndef BASE_PROCESS_H_ |
|
6 #define BASE_PROCESS_H_ |
|
7 |
|
8 #include "base/basictypes.h" |
|
9 |
|
10 #include <sys/types.h> |
|
11 #ifdef OS_WIN |
|
12 #include <windows.h> |
|
13 #endif |
|
14 |
|
15 namespace base { |
|
16 |
|
17 // ProcessHandle is a platform specific type which represents the underlying OS |
|
18 // handle to a process. |
|
19 // ProcessId is a number which identifies the process in the OS. |
|
20 #if defined(OS_WIN) |
|
21 typedef HANDLE ProcessHandle; |
|
22 typedef DWORD ProcessId; |
|
23 #elif defined(OS_POSIX) |
|
24 // On POSIX, our ProcessHandle will just be the PID. |
|
25 typedef pid_t ProcessHandle; |
|
26 typedef pid_t ProcessId; |
|
27 #endif |
|
28 |
|
29 class Process { |
|
30 public: |
|
31 Process() : process_(0), last_working_set_size_(0) {} |
|
32 explicit Process(ProcessHandle handle) : |
|
33 process_(handle), last_working_set_size_(0) {} |
|
34 |
|
35 // A handle to the current process. |
|
36 static Process Current(); |
|
37 |
|
38 // Get/Set the handle for this process. The handle will be 0 if the process |
|
39 // is no longer running. |
|
40 ProcessHandle handle() const { return process_; } |
|
41 void set_handle(ProcessHandle handle) { process_ = handle; } |
|
42 |
|
43 // Get the PID for this process. |
|
44 ProcessId pid() const; |
|
45 |
|
46 // Is the this process the current process. |
|
47 bool is_current() const; |
|
48 |
|
49 // Close the process handle. This will not terminate the process. |
|
50 void Close(); |
|
51 |
|
52 // Terminates the process with extreme prejudice. The given result code will |
|
53 // be the exit code of the process. If the process has already exited, this |
|
54 // will do nothing. |
|
55 void Terminate(int result_code); |
|
56 |
|
57 // A process is backgrounded when it's priority is lower than normal. |
|
58 // Return true if this process is backgrounded, false otherwise. |
|
59 bool IsProcessBackgrounded() const; |
|
60 |
|
61 // Set a prcess as backgrounded. If value is true, the priority |
|
62 // of the process will be lowered. If value is false, the priority |
|
63 // of the process will be made "normal" - equivalent to default |
|
64 // process priority. |
|
65 // Returns true if the priority was changed, false otherwise. |
|
66 bool SetProcessBackgrounded(bool value); |
|
67 |
|
68 // Releases as much of the working set back to the OS as possible. |
|
69 // Returns true if successful, false otherwise. |
|
70 bool EmptyWorkingSet(); |
|
71 |
|
72 private: |
|
73 ProcessHandle process_; |
|
74 size_t last_working_set_size_; |
|
75 }; |
|
76 |
|
77 } // namespace base |
|
78 |
|
79 #endif // BASE_PROCESS_H_ |