On Windows, the function for this is Sleep
, which takes the milliseconds you want to sleep. To use Sleep
, you need to enable windows.h
.
On POSIX systems, the Sleep
function (from unistd.h
) does the following:
unsigned int sleep(unsigned int seconds); DESCRIPTION sleep() makes the calling thread sleep until seconds seconds have elapsed or a signal arrives which is not ignored.
If the signal is interrupted by the signal, the remaining timeout is returned. If you use signals, a more reliable solution would be:
unsigned int time_to_sleep = 10; // sleep 10 seconds while(time_to_sleep) time_to_sleep = sleep(time_to_sleep);
This, of course, assumes that your signal handlers take up only a small amount of time. (Otherwise, this will delay the main program longer than expected)
source share