I am creating a process with CreateProcess
:
- with flags
CREATE_NO_WINDOW | CREATE_BREAKAWAY_FROM_JOB | CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
InheritHandles
param =TRUE
- startupinfo stdout and stderr file redirection (
STARTF_USESTDHANDLES
) SECURITY_ATTRIBUTES.InheritHandle = TRUE
The handle the the process is closed while it continues its execution.
Then I am checking the process state by getting the handle for process with given PID:
HANDLE HProcess = OpenProcess(
PROCESS_QUERY_INFORMATION , TRUE, task->taskPid);
Edit: Yes, I am checking whether the returned process is really the process I queried for:
if ( ( HProcess != NULL ) && ( GetProcessId(HProcess) != requestedPid ) )
Regardless of whether the created process is really running or not, I am getting a valid handle to the process. If I restart my application, the check code works properly. I suspect that the handle is somehow buffered, or the created process is in the same group - but I can't seem to find any information about it in the documentation.