I need to check if a process with a given HANDLE is still running, I tried to do it using the following code however it always returns at the second return false, even if the process is running.
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
}
You can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time. This will display the process for the current shell with four columns: PID returns the unique process ID.
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
You can test the process life by using
bool isProcessRunning(HANDLE process)
{
return WaitForSingleObject( process, 0 ) == WAIT_TIMEOUT;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With