Home > Net >  On Windows do I *have to* call WaitForSingleObject() after calling CreateProcess()?
On Windows do I *have to* call WaitForSingleObject() after calling CreateProcess()?

Time:10-29

On Linux, I have to call wait() after fork() on the parent process, otherwise the child process will stay zombie after completion until the parent process completes.

I wonder whether I must follow similar steps on Windows, i.e. whether I must call WaitForSingleObject() after calling CreateProcess().

I know that Windows' CreateProcess() is different from Linux's fork() and it seems that 'zombie' is a UNIX/Linux concept that does not exist on Windows. But maybe I still must call WaitForSingleObject() to free some OS resources allocated for CreateProcess(), similar to the Linux case.

CodePudding user response:

If CreateProcess succeeds you must close the two handles in PROCESS_INFORMATION but you don't have to wait for the child process first, the handles can be closed at any point if you don't need them.

A open handle to a process will keep the process object alive in a zombie state after it has finished running.

  • Related