Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cOSProcess Class Reference

#include <cOSProcess.h>

Inheritance diagram for Gray::cOSProcess:
GrayLib::cOSProcessX

Public Member Functions

 cOSProcess () noexcept
 
virtual ~cOSProcess ()
 
HRESULT CreateProcessX (const FILECHAR_t *pszExeName, const FILECHAR_t *pszArgs=nullptr, SHOWWINDOW_t nShowCmd=SW_SHOWNORMAL, const FILECHAR_t *pszCurrentDir=nullptr, cFile *pFileOutPipe=nullptr)
 
bool isValidProcess () const noexcept
 
PROCESSID_t get_ProcessId () const noexcept
 
virtual cStringF get_ProcessPath () const
 
cStringF get_ProcessName () const
 
HRESULT OpenProcessId (PROCESSID_t dwProcessID, DWORD dwDesiredAccess=0, bool bInheritHandle=false)
 
cStringF get_CommandLine () const
 
HRESULT WaitForProcessExit (TIMESYSD_t nTimeWait, APP_EXITCODE_t *pnExitCode=nullptr)
 
void AttachCurrentProcess () noexcept
 
HRESULT TerminateProcess (APP_EXITCODE_t uExitCode)
 
DWORD get_PriorityClass () const noexcept
 CPU priority level for scheduling. More...
 
bool put_PriorityClass (DWORD dwPriorityClass) noexcept
 

Static Public Member Functions

static bool __stdcall IsSystemPID (PROCESSID_t nProcessID) noexcept
 

Protected Attributes

PROCESSID_t m_nPid
 Process ID, 0 = PROCESSID_BAD = un-init. More...
 

Friends

class cOSProcessTests
 

Detailed Description

A running process in the system. May or may not be the current process. handle to some active process I started (me or my child). Related to MIME_EXT_exe PROCESSID_t. Related to cOSModule.

Constructor & Destructor Documentation

◆ cOSProcess()

Gray::cOSProcess::cOSProcess ( )
noexcept

◆ ~cOSProcess()

Gray::cOSProcess::~cOSProcess ( )
virtual

Member Function Documentation

◆ AttachCurrentProcess()

void Gray::cOSProcess::AttachCurrentProcess ( )
inlinenoexcept

No need to close this handle!

◆ CreateProcessX()

HRESULT Gray::cOSProcess::CreateProcessX ( const FILECHAR_t pszExeName,
const FILECHAR_t pszArgs = nullptr,
SHOWWINDOW_t  nShowCmd = SW_SHOWNORMAL,
const FILECHAR_t pszCurrentDir = nullptr,
cFile pFileOutPipe = nullptr 
)

Create/launch/spawn the child process file and get handle to it.

Note
DOES NOT expand things like programFiles% . use ExpandEnvironmentStrings()
  • pszExeName = the app file to start.
  • pszCurrentDir = cFilePath::GetFileDir( pszExeName ) similar to POSIX execvp()

◆ get_CommandLine()

cStringF Gray::cOSProcess::get_CommandLine ( ) const

Get the full command line arguments for the process by id. "App.exe Args" like _WIN32 "::GetCommandLine()"

◆ get_PriorityClass()

DWORD Gray::cOSProcess::get_PriorityClass ( ) const
inlinenoexcept

CPU priority level for scheduling.

ABOVE_NORMAL_PRIORITY_CLASS

◆ get_ProcessId()

PROCESSID_t Gray::cOSProcess::get_ProcessId ( ) const
inlinenoexcept

◆ get_ProcessName()

cStringF Gray::cOSProcess::get_ProcessName ( ) const

Get a process name from a handle. like GetModuleBaseName() _WIN32 must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights.

◆ get_ProcessPath()

cStringF Gray::cOSProcess::get_ProcessPath ( ) const
virtual

Get the full file path for this process EXE. MUST be loaded by this process for _WIN32. e.g. "c:\Windows\System32\smss.exe" or "\Device\HarddiskVolume2\Windows\System32\smss.exe"

Note
_WIN32 must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights.

◆ IsSystemPID()

static bool __stdcall Gray::cOSProcess::IsSystemPID ( PROCESSID_t  nProcessID)
inlinestaticnoexcept

◆ isValidProcess()

bool Gray::cOSProcess::isValidProcess ( ) const
inlinenoexcept

◆ OpenProcessId()

HRESULT Gray::cOSProcess::OpenProcessId ( PROCESSID_t  dwProcessID,
DWORD  dwDesiredAccess = 0,
bool  bInheritHandle = false 
)

get a handle to a process by its PROCESSID_t.

  • dwDesiredAccess = PROCESS_TERMINATE | PROCESS_VM_READ

◆ put_PriorityClass()

bool Gray::cOSProcess::put_PriorityClass ( DWORD  dwPriorityClass)
inlinenoexcept

Set the threads priority.

  • dwPriorityClass = ABOVE_NORMAL_PRIORITY_CLASS

◆ TerminateProcess()

HRESULT Gray::cOSProcess::TerminateProcess ( APP_EXITCODE_t  uExitCode)
inline

terminate some process. inject uExitCode. m_nPid may be invalid after this!

◆ WaitForProcessExit()

HRESULT Gray::cOSProcess::WaitForProcessExit ( TIMESYSD_t  nTimeWait,
APP_EXITCODE_t *  pnExitCode = nullptr 
)

Wait for a process to exit.

  • nTimeWait = how long to wait in seconds. 0 = dont wait. (Does NOT terminate app) It is generally assumed this is a child process of the current PROCESSID_t (Linux)
    Note
    this does not CAUSE the process to exit.

Friends And Related Function Documentation

◆ cOSProcessTests

friend class cOSProcessTests
friend

Member Data Documentation

◆ m_nPid

PROCESSID_t Gray::cOSProcess::m_nPid
protected

Process ID, 0 = PROCESSID_BAD = un-init.


The documentation for this class was generated from the following files: