Fir*_*cer 5 c++ windows process
我需要检查具有给定HANDLE的进程是否仍在运行,我尝试使用以下代码执行此操作,但它始终返回第二个返回false,即使进程正在运行.
bool isProcessRunning(HANDLE process)
{
if(process == INVALID_HANDLE_VALUE)return false;
DWORD exitCode;
if(GetExitCodeProcess(process, &exitCode) != 0)
return false;//always returns here
return GetLastError() == STILL_ACTIVE;//still running
}
Run Code Online (Sandbox Code Playgroud)
您可以使用测试过程寿命
bool isProcessRunning(HANDLE process)
{
return WaitForSingleObject( process, 0 ) == WAIT_TIMEOUT;
}
Run Code Online (Sandbox Code Playgroud)