Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a process started with CreateProcess is still running?

If I've got a process created through CreateProcess(), how would I determine if it's still running? I know I need to use pi.hProcess but I don't know how, and google isn't really giving me meaningful hints.

PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
bool got_it=CreateProcess(NULL, CA2T(launchString.c_str()), NULL, NULL, false, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
like image 261
Carbon Avatar asked Nov 14 '25 09:11

Carbon


1 Answers

You can use any of the standard wait functions, like WaitForSingleObject(), eg:

switch (WaitForSingleObject(pi.hProcess, 0))
{
    case WAIT_OBJECT_0:
        // process has terminated...
        break;

    case WAIT_TIMEOUT:
        // process is still running...
        break;
}
like image 104
Remy Lebeau Avatar answered Nov 17 '25 10:11

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!