1 // Copyright (c) 2011 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.
5 #ifndef BASE_PROCESS_H_
6 #define BASE_PROCESS_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "build/build_config.h"
12 #include <sys/types.h>
19 // ProcessHandle is a platform specific type which represents the underlying OS
20 // handle to a process.
21 // ProcessId is a number which identifies the process in the OS.
23 typedef HANDLE ProcessHandle
;
24 typedef DWORD ProcessId
;
25 typedef HANDLE UserTokenHandle
;
26 const ProcessHandle kNullProcessHandle
= NULL
;
27 const ProcessId kNullProcessId
= 0;
28 #elif defined(OS_POSIX)
29 // On POSIX, our ProcessHandle will just be the PID.
30 typedef pid_t ProcessHandle
;
31 typedef pid_t ProcessId
;
32 const ProcessHandle kNullProcessHandle
= 0;
33 const ProcessId kNullProcessId
= 0;
34 #endif // defined(OS_WIN)
36 class BASE_EXPORT Process
{
38 Process() : process_(kNullProcessHandle
) {
41 explicit Process(ProcessHandle handle
) : process_(handle
) {
44 // A handle to the current process.
45 static Process
Current();
47 static bool CanBackgroundProcesses();
49 // Get/Set the handle for this process. The handle will be 0 if the process
50 // is no longer running.
51 ProcessHandle
handle() const { return process_
; }
52 void set_handle(ProcessHandle handle
) {
56 // Get the PID for this process.
57 ProcessId
pid() const;
59 // Is the this process the current process.
60 bool is_current() const;
62 // Close the process handle. This will not terminate the process.
65 // Terminates the process with extreme prejudice. The given result code will
66 // be the exit code of the process. If the process has already exited, this
68 void Terminate(int result_code
);
70 // A process is backgrounded when it's priority is lower than normal.
71 // Return true if this process is backgrounded, false otherwise.
72 bool IsProcessBackgrounded() const;
74 // Set a process as backgrounded. If value is true, the priority
75 // of the process will be lowered. If value is false, the priority
76 // of the process will be made "normal" - equivalent to default
78 // Returns true if the priority was changed, false otherwise.
79 bool SetProcessBackgrounded(bool value
);
81 // Returns an integer representing the priority of a process. The meaning
82 // of this value is OS dependent.
83 int GetPriority() const;
86 ProcessHandle process_
;
91 #endif // BASE_PROCESS_H_