Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make C program wait (on Linux)?

Tags:

c

linux

wait

mpi

How to make C program wait (on Linux)? (I need to use wait with MPI - I need C code please)

like image 907
Rella Avatar asked Apr 02 '10 10:04

Rella


People also ask

How do you wait in C programming?

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".

Is there a wait in C?

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.

What is sleep () in C?

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.

What library is wait () in?

C library/kernel differences wait() is actually a library function that (in glibc) is implemented as a call to wait4(2).


2 Answers

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.

like image 63
INS Avatar answered Sep 29 '22 06:09

INS


You can use sleep(seconds)

like image 28
Thomas Bonini Avatar answered Sep 29 '22 05:09

Thomas Bonini