Some caution is required. Using the standard library's meagre time services you have to resort to polling the time as in @DRK82's solution. Such "busy-wait" loops will consume as much CPU time as the OS will allow it and may adversely affect other processes and the general responsiveness of your system.

A better approach is to use timing services provided by the OS so that during the waiting period your processor is free to do other tasks. For example in Windows:

Some caution is required. Using the standard library's meagre time services you have to resort to polling the time as in @DRK82's solution. Such "busy-wait" loops will consume as much CPU time as the OS will allow it and may adversely affect other processes and the general responsiveness of your system.

A better approach is to use timing services provided by the OS so that during the waiting period your processor is free to do other tasks. For example in Windows:

is there a way to get time from the real time clock on the motherboard? and update using that? (or were the methods you posted already using that ?)

Firstly no need to quite my entire post!

To output at 10 minute periods you don't need a clock time just a period measurement. If you want an "alarm clock", you could for example, sleep for 1 second, check the real time using the standard time.h functions, then go back to sleep. That would be less wasteful of CPU time.

To output at 10 minute periods you don't need a clock time just a period measurement. If you want an "alarm clock", you could for example, sleep for 1 second, check the real time using the standard time.h functions, then go back to sleep. That would be less wasteful of CPU time.

sorry I didn't understand. How does the sleep function work?

I've only known of one way to make a delay which is to use a while loop. the real time clock on the mother board my guess is works on a similar principle, a timer that keeps looping, has a fixed frequency and adds a second to the time after one second worth of counts, power using a cell so it doesn't loose time when u plug ur pc off...

Sleeping a process uses the operating systems scheduler switch completely stop a process for a period of time. The time can then be used by other processes. If a process "busy-waits" in a loop it will demand CPU cycles to do essentially nothing. Sleep behaviour prevents your process from adversely affecting the performance of the system as a whole.

Sleeping a process uses the operating systems scheduler switch completely stop a process for a period of time. The time can then be used by other processes. If a process "busy-waits" in a loop it will demand CPU cycles to do essentially nothing. Sleep behaviour prevents your process from adversely affecting the performance of the system as a whole.