I have a console application running on a NT workstation.
It spawns off one or more instances of a child program using CreateProcess. It retains each child's Process ID and periodically checks if the children are alive or not, using OpenProcess.
The OpenProcess sometimes returns a NULL handle even if the child process is alive. This seems to happen when the NT server is really really busy - the child processes do some heavy number crunching.
Any suggestions ?
int main( int argc, char *argv )
STARTUPINFO si =
sizeof(STARTUPINFO), NULL, NULL, NULL, 0,0,0,0,0,0,0, STARTF_USESHOWWINDOW, SW_SHOWNORMAL, 0, NULL, 0, 0, 0
if ( !CreateProcess(NULL, (char *)aCommand.data(), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi) )
cout << "Failed to start Child Process, CreateProcess returned " << GetLastError() << endl;
cout << "Child Process ID is " << pi.dwProcessId << endl;
bool isActive( DWORD ProcessID )
//Get handle to process
HANDLE handle = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, ProcessID );
if ( handle != NULL )
if ( GetExitCodeProcess( handle, &Value ) && ( Value == (DWORD)STILL_ACTIVE ) )