7 #ifndef _INC_cOSProcess_H
8 #define _INC_cOSProcess_H
22 typedef int SHOWWINDOW_t;
23 #elif defined(__linux__)
40 typedef DWORD PROCESSID_t;
41 typedef DWORD APP_EXITCODE_t;
42 #elif defined(__linux__)
43 typedef pid_t PROCESSID_t;
44 typedef int APP_EXITCODE_t;
60 APP_EXITCODE_STILL_ACTIVE = STILL_ACTIVE,
61 #elif defined(__linux__)
62 APP_EXITCODE_STILL_ACTIVE = 0x103,
81 #elif defined(__linux__)
93 cOSProcess(PROCESSID_t nPid, HANDLE h) noexcept
99 HANDLE get_ProcessHandle() const noexcept
103 void CloseProcessHandle();
105 HRESULT CreateProcessX(
const FILECHAR_t* pszExeName,
const FILECHAR_t* pszArgs =
nullptr, SHOWWINDOW_t nShowCmd = SW_SHOWNORMAL,
const FILECHAR_t* pszCurrentDir =
nullptr, cFile* pFileOutPipe =
nullptr);
123 #elif defined(__linux__)
132 virtual cStringF get_ProcessPath()
const;
134 HRESULT OpenProcessId(PROCESSID_t dwProcessID, DWORD dwDesiredAccess = 0,
bool bInheritHandle =
false);
137 HRESULT GetProcessCommandLine(OUT
wchar_t* pwText, _Inout_
size_t* pdwTextSize)
const;
141 HRESULT WaitForProcessExit(
TIMESYSD_t nTimeWait, APP_EXITCODE_t* pnExitCode =
nullptr);
148 m_nPid = ::GetCurrentProcessId();
150 #elif defined(__linux__)
160 if (!isValidProcess())
163 if (!::TerminateProcess(get_ProcessHandle(), uExitCode))
164 #elif defined(__linux__)
165 if (::kill(get_ProcessId(), SIGTERM) != 0)
177 #if defined(_WIN32) && ! defined(UNDER_CE)
178 return ::GetPriorityClass(get_ProcessHandle());
179 #elif defined(__linux__)
189 #if defined(_WIN32) && ! defined(UNDER_CE)
190 return ::SetPriorityClass(get_ProcessHandle(), dwPriorityClass) ? true :
false;
191 #elif defined(__linux__)
202 void* AllocMemory(
size_t nSize)
205 return ::VirtualAllocEx(get_ProcessHandle(), NULL, nSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
208 HRESULT WriteProcessMemory(
void* pBaseAddress,
const void* pData,
size_t nSize)
213 SIZE_T nSizeWrite = nSize;
214 const BOOL bSuccess = ::WriteProcessMemory(get_ProcessHandle(), pBaseAddress, pData, nSize, &nSizeWrite);
222 HRESULT ReadProcessMemory(
const void* pBaseAddress,
void* pDataIn,
size_t nSize)
const
228 SIZE_T nSizeRead = nSize;
229 const BOOL bSuccess = ::ReadProcessMemory(get_ProcessHandle(), pBaseAddress, pDataIn, nSize, &nSizeRead);
237 bool GetExitCodeProcess(OUT APP_EXITCODE_t* pnExitCode)
242 return ::GetExitCodeProcess(get_ProcessHandle(), pnExitCode) ? true :
false;
245 static inline PROCESSID_t FindProcessIdForWindow(HWND hWnd) noexcept
250 const THREADID_t dwThreadID = ::GetWindowThreadProcessId(hWnd, &dwProcessIDRet);
252 return dwProcessIDRet;
257 bool GetStatTimes(OUT FILETIME* pCreationTime, OUT FILETIME* pExitTime, OUT FILETIME* pKernelTime, OUT FILETIME* pUserTime)
const
260 return ::GetProcessTimes(get_ProcessHandle(), pCreationTime, pExitTime, pKernelTime, pUserTime) ? true :
false;
263 bool GetStatIoCounters(OUT IO_COUNTERS* pIoCounters)
const
265 return ::GetProcessIoCounters(get_ProcessHandle(), pIoCounters) ? true :
false;
269 #if ( _WIN32_WINNT >= 0x0501 ) && ! defined(UNDER_CE)
270 bool GetStatHandleCount(OUT DWORD* pdwHandleCount)
const
273 return ::GetProcessHandleCount(get_ProcessHandle(), pdwHandleCount);
276 static HWND
GRAYCALL FindWindowForProcessID(PROCESSID_t nProcessID, DWORD dwStyleFlags,
const GChar_t* pszClassName =
nullptr);
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define HRESULT_WIN32_C(x)
a constant LSTATUS/error_status_t with no check, unlike HRESULT_FROM_WIN32()
Definition: HResult.h:79
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
static HRESULT GetLastDef(HRESULT hResDef=E_FAIL) noexcept
Definition: HResult.h:242
Definition: cOSHandle.h:59
void AttachHandle(HANDLE h) noexcept
Definition: cOSHandle.h:163
bool isValidHandle() const noexcept
Definition: cOSHandle.h:125
HANDLE get_Handle() const noexcept
Definition: cOSHandle.h:107
Definition: cOSProcess.h:68
PROCESSID_t get_ProcessId() const noexcept
Definition: cOSProcess.h:128
void AttachCurrentProcess() noexcept
Definition: cOSProcess.h:143
HRESULT TerminateProcess(APP_EXITCODE_t uExitCode)
Definition: cOSProcess.h:155
bool put_PriorityClass(DWORD dwPriorityClass) noexcept
Definition: cOSProcess.h:185
bool isValidProcess() const noexcept
Definition: cOSProcess.h:118
PROCESSID_t m_nPid
Process ID, 0 = PROCESSID_BAD = un-init.
Definition: cOSProcess.h:75
static bool __stdcall IsSystemPID(PROCESSID_t nProcessID) noexcept
Definition: cOSProcess.h:107
DWORD get_PriorityClass() const noexcept
CPU priority level for scheduling.
Definition: cOSProcess.h:174
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
constexpr PROCESSID_t PROCESSID_BAD
Invalid process id.
Definition: cOSProcess.h:46
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
THREAD_EXITCODE_t(_stdcall * THREAD_FUNC_t)(void *)
Definition: cThreadLock.h:52
APP_EXITCODE_TYPE
Definition: cOSProcess.h:49
@ APP_EXITCODE_OK
0=EXIT_SUCCESS (stdlib.h). App closed.
Definition: cOSProcess.h:54
@ APP_EXITCODE_UNK
handle not valid ?
Definition: cOSProcess.h:64
@ APP_EXITCODE_ABORT
3=Default error returned if "abort()" used (arbitrary?) App closed.
Definition: cOSProcess.h:56
@ APP_EXITCODE_ERRNO
See Posix 'errno' for why this process never started.
Definition: cOSProcess.h:53
@ APP_EXITCODE_FAIL
1=EXIT_FAILURE = generic error. App closed.
Definition: cOSProcess.h:55