michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_PROCESS_H_ michael@0: #define BASE_PROCESS_H_ michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: #include michael@0: #ifdef OS_WIN michael@0: #include michael@0: #endif michael@0: michael@0: namespace base { michael@0: michael@0: // ProcessHandle is a platform specific type which represents the underlying OS michael@0: // handle to a process. michael@0: // ProcessId is a number which identifies the process in the OS. michael@0: #if defined(OS_WIN) michael@0: typedef HANDLE ProcessHandle; michael@0: typedef DWORD ProcessId; michael@0: #elif defined(OS_POSIX) michael@0: // On POSIX, our ProcessHandle will just be the PID. michael@0: typedef pid_t ProcessHandle; michael@0: typedef pid_t ProcessId; michael@0: #endif michael@0: michael@0: class Process { michael@0: public: michael@0: Process() : process_(0), last_working_set_size_(0) {} michael@0: explicit Process(ProcessHandle handle) : michael@0: process_(handle), last_working_set_size_(0) {} michael@0: michael@0: // A handle to the current process. michael@0: static Process Current(); michael@0: michael@0: // Get/Set the handle for this process. The handle will be 0 if the process michael@0: // is no longer running. michael@0: ProcessHandle handle() const { return process_; } michael@0: void set_handle(ProcessHandle handle) { process_ = handle; } michael@0: michael@0: // Get the PID for this process. michael@0: ProcessId pid() const; michael@0: michael@0: // Is the this process the current process. michael@0: bool is_current() const; michael@0: michael@0: // Close the process handle. This will not terminate the process. michael@0: void Close(); michael@0: michael@0: // Terminates the process with extreme prejudice. The given result code will michael@0: // be the exit code of the process. If the process has already exited, this michael@0: // will do nothing. michael@0: void Terminate(int result_code); michael@0: michael@0: // A process is backgrounded when it's priority is lower than normal. michael@0: // Return true if this process is backgrounded, false otherwise. michael@0: bool IsProcessBackgrounded() const; michael@0: michael@0: // Set a prcess as backgrounded. If value is true, the priority michael@0: // of the process will be lowered. If value is false, the priority michael@0: // of the process will be made "normal" - equivalent to default michael@0: // process priority. michael@0: // Returns true if the priority was changed, false otherwise. michael@0: bool SetProcessBackgrounded(bool value); michael@0: michael@0: // Releases as much of the working set back to the OS as possible. michael@0: // Returns true if successful, false otherwise. michael@0: bool EmptyWorkingSet(); michael@0: michael@0: private: michael@0: ProcessHandle process_; michael@0: size_t last_working_set_size_; michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_PROCESS_H_