What is the benefit of using WaitForSingleObject
here as opposed to not using it? The first block of code is from a previous answer. The second block is how I am doing it.
BOOL IsProcessRunning(DWORD pid)
{
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
DWORD ret = WaitForSingleObject(process, 0);
CloseHandle(process);
return (ret == WAIT_TIMEOUT);
}
vs
BOOL IsProcessRunning(DWORD pid)
{
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
const bool exists = (process != NULL);
CloseHandle(process);
return exists;
}
It seems like using SYNCHRONIZE requires higher privileges and I only want to check the PID for the current user.