I need to catch process termination signals for child processes.
So for example, if my Win32 console application spawns a notepad process and the user closes notepad, I would like to detect that.
I don’t want to block (asynchronous model)
I’m creating a process using the win api CreateProcess
Have you tried
WaitForSingleObject()with it’sdwMillisecondsparameter as 0?WaitForSingleObject()will return immediately ifdwMillisecondsis 0 and will returnWAIT_TIMEOUTif the process isn’t dead orWAIT_OBJECT_0if it is.Example, assuming the child process handle is
hProcess:And alternative is
GetExitCodeProcess(). The “exit code” returned by it will beSTILL_ACTIVEif it is still running, otherwise it will return the actual exit code.Example, again assuming the child process handle is
hProcess:Both these examples are non-blocking