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_PROCESS_PROCESS_H_
6 #define BASE_PROCESS_PROCESS_PROCESS_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/move.h"
11 #include "base/process/process_handle.h"
12 #include "build/build_config.h"
15 #include "base/win/scoped_handle.h"
20 // Provides a move-only encapsulation of a process.
22 // This object is not tied to the lifetime of the underlying process: the
23 // process may be killed and this object may still around, and it will still
24 // claim to be valid. The actual behavior in that case is OS dependent like so:
26 // Windows: The underlying ProcessHandle will be valid after the process dies
27 // and can be used to gather some information about that process, but most
28 // methods will obviously fail.
30 // POSIX: The underlying PorcessHandle is not guaranteed to remain valid after
31 // the process dies, and it may be reused by the system, which means that it may
32 // end up pointing to the wrong process.
33 class BASE_EXPORT Process {
34 MOVE_ONLY_TYPE_FOR_CPP_03(Process, RValue)
37 explicit Process(ProcessHandle handle = kNullProcessHandle);
39 // Move constructor for C++03 move emulation of this type.
40 Process(RValue other);
42 // The destructor does not terminate the process.
45 // Move operator= for C++03 move emulation of this type.
46 Process& operator=(RValue other);
48 // Returns an object for the current process.
49 static Process Current();
51 // Returns true if processes can be backgrounded.
52 static bool CanBackgroundProcesses();
54 // Returns true if this objects represents a valid process.
57 // Returns a handle for this process. There is no guarantee about when that
58 // handle becomes invalid because this object retains ownership.
59 ProcessHandle Handle() const;
61 // Returns a second object that represents this process.
62 Process Duplicate() const;
64 // Get the PID for this process.
65 ProcessId pid() const;
67 // Returns true if this process is the current process.
68 bool is_current() const;
70 // Close the process handle. This will not terminate the process.
73 // Terminates the process with extreme prejudice. The given |result_code| will
74 // be the exit code of the process.
75 // NOTE: On POSIX |result_code| is ignored.
76 void Terminate(int result_code);
78 // A process is backgrounded when it's priority is lower than normal.
79 // Return true if this process is backgrounded, false otherwise.
80 bool IsProcessBackgrounded() const;
82 // Set a process as backgrounded. If value is true, the priority of the
83 // process will be lowered. If value is false, the priority of the process
84 // will be made "normal" - equivalent to default process priority.
85 // Returns true if the priority was changed, false otherwise.
86 bool SetProcessBackgrounded(bool value);
88 // Returns an integer representing the priority of a process. The meaning
89 // of this value is OS dependent.
90 int GetPriority() const;
94 bool is_current_process_;
95 win::ScopedHandle process_;
97 ProcessHandle process_;
103 #endif // BASE_PROCESS_PROCESS_PROCESS_H_