Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #ifndef BASE_PROCESS_H_
8 : #define BASE_PROCESS_H_
9 :
10 : #include "base/basictypes.h"
11 :
12 : #include <sys/types.h>
13 : #ifdef OS_WIN
14 : #include <windows.h>
15 : #endif
16 :
17 : namespace base {
18 :
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.
22 : #if defined(OS_WIN)
23 : typedef HANDLE ProcessHandle;
24 : typedef DWORD ProcessId;
25 : #elif defined(OS_POSIX)
26 : // On POSIX, our ProcessHandle will just be the PID.
27 : typedef pid_t ProcessHandle;
28 : typedef pid_t ProcessId;
29 : #endif
30 :
31 : class Process {
32 : public:
33 : Process() : process_(0), last_working_set_size_(0) {}
34 2 : explicit Process(ProcessHandle aHandle) :
35 2 : process_(aHandle), last_working_set_size_(0) {}
36 :
37 : // A handle to the current process.
38 : static Process Current();
39 :
40 : // Get/Set the handle for this process. The handle will be 0 if the process
41 : // is no longer running.
42 : ProcessHandle handle() const { return process_; }
43 : void set_handle(ProcessHandle aHandle) { process_ = aHandle; }
44 :
45 : // Get the PID for this process.
46 : ProcessId pid() const;
47 :
48 : // Is the this process the current process.
49 : bool is_current() const;
50 :
51 : // Close the process handle. This will not terminate the process.
52 : void Close();
53 :
54 : // Terminates the process with extreme prejudice. The given result code will
55 : // be the exit code of the process. If the process has already exited, this
56 : // will do nothing.
57 : void Terminate(int result_code);
58 :
59 : // A process is backgrounded when it's priority is lower than normal.
60 : // Return true if this process is backgrounded, false otherwise.
61 : bool IsProcessBackgrounded() const;
62 :
63 : // Set a prcess as backgrounded. If value is true, the priority
64 : // of the process will be lowered. If value is false, the priority
65 : // of the process will be made "normal" - equivalent to default
66 : // process priority.
67 : // Returns true if the priority was changed, false otherwise.
68 : bool SetProcessBackgrounded(bool value);
69 :
70 : // Releases as much of the working set back to the OS as possible.
71 : // Returns true if successful, false otherwise.
72 : bool EmptyWorkingSet();
73 :
74 : private:
75 : ProcessHandle process_;
76 : size_t last_working_set_size_;
77 : };
78 :
79 : } // namespace base
80 :
81 : #endif // BASE_PROCESS_H_
|