Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for a process to finish C++

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++ ?

like image 294
01BTC10 Avatar asked Feb 26 '12 14:02

01BTC10


People also ask

How do you make your parents wait for all child processes to finish?

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.

What does wait () do?

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.

What is the difference between wait () and waitpid ()?

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.


1 Answers

You just call WaitForSingleObject on the handle CreateProcess returns.

like image 63
Nikola Smiljanić Avatar answered Sep 20 '22 15:09

Nikola Smiljanić