I wrote a little console application, and I want it to pause for a certain number of seconds before the cycle (a while) starts again.
I’m working on Windows operating system.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
On Windows, the function to do this is
Sleep, which takes the amount of milliseconds you want to sleep. To useSleep, you need to includewindows.h.On POSIX-Systems, the function
sleep(fromunistd.h) accomplishes this:If it is interrupted by a signal, the remaining time to sleep is returned. If you use signals, a more robust solution would be:
This is of course assuming your signal-handlers only take a negligible amount of time. (Otherwise, this will delay the main program longer than intended)