How to make C program wait (on Linux)? (I need to use wait with MPI - I need C code please)
Insert, wherever you need your program to make a delay:sleep(1000); Change the "1000" to the number of milliseconds you want to wait (for example, if you want to make a 2 second delay, replace it with "2000".
A call to wait() blocks the calling process until one of its child processes exits or a signal is received. After child process terminates, parent continues its execution after wait system call instruction.
Return Value The sleep() function in C returns 0 if the requested time has elapsed. Due to signal transmission sleep() returns the unslept quantity, a difference between the requested time to sleep() and the time it actually slept in seconds.
C library/kernel differences wait() is actually a library function that (in glibc) is implemented as a call to wait4(2).
If you want to wait for a MPI request use MPI_Wait: http://www.manpagez.com/man/3/MPI_Wait/
If you want to wait a certain amount of time use sleep: http://www.manpagez.com/man/3/Sleep/
If you want to wait another process to end use waitpid: http://linux.die.net/man/2/waitpid
If you want to wait a condition variable (multi-threaded programming) use pthread_cond_wait: http://www.opengroup.org/onlinepubs/007908775/xsh/pthread_cond_wait.html
Define what you want to wait for.
You can use sleep(seconds)
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