123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- #ifndef BASE_PROCESS_PROCESS_H_
- #define BASE_PROCESS_PROCESS_H_
- #include "base/base_export.h"
- #include "base/macros.h"
- #include "base/process/process_handle.h"
- #include "base/time/time.h"
- #include "build/build_config.h"
- #include "build/chromeos_buildflags.h"
- #if defined(OS_WIN)
- #include "base/win/scoped_handle.h"
- #endif
- #if defined(OS_FUCHSIA)
- #include <lib/zx/process.h>
- #endif
- #if defined(OS_APPLE)
- #include "base/feature_list.h"
- #include "base/process/port_provider_mac.h"
- #endif
- namespace base {
- #if defined(OS_APPLE)
- extern const Feature kMacAllowBackgroundingProcesses;
- #endif
- class BASE_EXPORT Process {
- public:
-
-
- explicit Process(ProcessHandle handle = kNullProcessHandle);
- Process(Process&& other);
-
- ~Process();
- Process& operator=(Process&& other);
-
- static Process Current();
-
- static Process Open(ProcessId pid);
-
-
-
- static Process OpenWithExtraPrivileges(ProcessId pid);
- #if defined(OS_WIN)
-
-
- static Process OpenWithAccess(ProcessId pid, DWORD desired_access);
- #endif
-
-
-
-
- static Process DeprecatedGetProcessFromHandle(ProcessHandle handle);
-
- static bool CanBackgroundProcesses();
-
- [[noreturn]] static void TerminateCurrentProcessImmediately(int exit_code);
-
- bool IsValid() const;
-
-
- ProcessHandle Handle() const;
-
- Process Duplicate() const;
-
- ProcessId Pid() const;
-
-
-
-
-
-
-
- Time CreationTime() const;
-
- bool is_current() const;
-
- void Close();
-
-
-
-
- #if defined(OS_WIN)
- bool IsRunning() const {
- return !WaitForExitWithTimeout(base::TimeDelta(), nullptr);
- }
- #endif
-
-
-
-
-
- bool Terminate(int exit_code, bool wait) const;
- #if defined(OS_WIN)
- enum class WaitExitStatus {
- PROCESS_EXITED,
- STOP_EVENT_SIGNALED,
- FAILED,
- };
-
-
-
- WaitExitStatus WaitForExitOrEvent(
- const base::win::ScopedHandle& stop_event_handle,
- int* exit_code) const;
- #endif
-
-
-
-
-
-
- bool WaitForExit(int* exit_code) const;
-
-
-
- bool WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const;
-
-
-
-
-
- void Exited(int exit_code) const;
- #if defined(OS_APPLE)
-
-
-
-
-
-
-
-
-
-
- bool IsProcessBackgrounded(PortProvider* port_provider) const;
-
-
-
-
-
-
-
- bool SetProcessBackgrounded(PortProvider* port_provider, bool value);
- #else
-
-
- bool IsProcessBackgrounded() const;
-
-
-
-
- bool SetProcessBackgrounded(bool value);
- #endif
-
-
- int GetPriority() const;
- #if defined(OS_CHROMEOS)
-
-
-
- ProcessId GetPidInNamespace() const;
- #endif
- private:
- #if defined(OS_WIN)
- win::ScopedHandle process_;
- #elif defined(OS_FUCHSIA)
- zx::process process_;
- #else
- ProcessHandle process_;
- #endif
- #if defined(OS_WIN) || defined(OS_FUCHSIA)
- bool is_current_process_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(Process);
- };
- #if defined(OS_CHROMEOS) || BUILDFLAG(IS_LACROS)
- BASE_EXPORT bool IsProcessBackgroundedCGroup(
- const StringPiece& cgroup_contents);
- #endif
- }
- #endif
|