tags:

views:

68

answers:

2

I am writing a program that will need to measure time in minutes.

To be exact, it will wait 10 minutes, execute some code, wait 2 minutes, execute more code and repeat this 5 times (anyone guess what I'm trying to do?) and I am wondering how to do the breaks.

Thanks in advance!

Oh, and by the way, I'm on Mac.

+3  A: 
#include <stdio.h>
#include <unistd.h>
sleep(600); // sleep ten minutes
sleep(120); //sleep two minutes

OR if that doesn't work, it'll be usleep, which takes miliseconds as argument I believe. (1 second = 1000)

Robus
That did the trick, thanks!
Mark Szymanski
Note though that `sleep()` can wake up early if your process recieves a signal, so you will need to check how much time has actually elapsed (using eg. `clock_gettime(CLOCK_MONOTONIC, ...)` before and after the sleep) and possibly sleep again.
caf
+2  A: 

sleep(3)

Nikolai N Fetissov