Date: 2010may13
OS: Windows
Language: C/C++
Q. Win32: check if a process is running
A. Do it by attempting to get the exit code, like this:
BOOL IsProcessRunning(const HANDLE hProcess)
{
DWORD dwExitCode;
if (!GetExitCodeProcess(hProcess, &dwExitCode)) return FALSE;
return dwExitCode == STILL_ACTIVE;
}
void ExampleUse()
{
if (IsProcessRunning(hMyProcess))
{
printf("My process IS running\n");
}
else
{
printf("My process is NOT running\n");
}
}
If you just want to wait until a process is done it is better to do:
WaitForSingleObject(hProcess, INFINITE);