I tried to convey this clearly:
You cannot guarantee EXACTLY how long sleep is. You have to add some slop (fudge factor) in your seconds calculation one way or another, it is not going to work out perfectly every time - example assumes you have
POSIX compliant time - ie., no leap seconds.:
Code:
calculate duration of sleep:
time_t how_long_to_sleep=1800;
how_long_to_sleep-= time(NULL) % 1800;
sleep(!how_long_to_sleep ? 1800 : how_long_to_sleep);