I'm too bored to write code right now but what you are asking is really easy.
Either use a loop and put a sleep to suspend and wake the process every 2-3 seconds, in order to keep the CPU usage in a low level or use alarm.
Hope you know what signals and signal handling is.
alarm(3) sends a SIGALARM after 3 seconds.
if you define a signal handler for SIGALARM, every time a SIGALARM is sent, the signalhandler which is just a simple function will be executed.
Well what the hell... I'll give you some sample code:
Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void alarm_handler(int);
int main()
{
signal(SIGALRM,alarm_handler);
alarm(3);
while(1){}
}
void alarm_handler(int num)
{
fprintf(stderr,"Alarm signal catched\n");
alarm(3);
}