I am creating a process with that code:
CreateProcess(NULL, "process.exe", NULL, NULL, TRUE, 0, NULL, NULL, %ini_processo, %processo_info);
I need my code to wait for my process to finish before resuming. What is the method with C++ ?
Just use: while(wait(NULL) > 0); This ensures that you wait for ALL the child processes and only when all have returned, you move to the next instruction.
The wait() function will suspend execution of the calling thread until status information for one of its terminated child processes is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process.
wait() and waitpid() The wait() system call suspends execution of the calling process until one of its children terminates. The call wait(&wstatus) is equivalent to: waitpid(-1, &wstatus, 0); The waitpid() system call suspends execution of the calling process until a child specified by pid argument has changed state.
You just call WaitForSingleObject
on the handle CreateProcess
returns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With