What is the advantage of using WaitForSingleObject here rather than using it? The first block of code is the previous answer . The second block is how I do it.
BOOL IsProcessRunning(DWORD pid) { HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid); DWORD ret = WaitForSingleObject(process, 0); CloseHandle(process); return (ret == WAIT_TIMEOUT); }
against
BOOL IsProcessRunning(DWORD pid) { HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); const bool exists = (process != NULL); CloseHandle(process); return exists; }
It seems that using SYNCHRONIZE requires higher privileges, and I only want to check the PID for the current user.
user195488
source share