I'm trying to use setitimer to send out a SIGALRM, which in turns calls my handler function to print to stdout. I've been scouring the internet for hours now and there is simply no clear indication on how setitimer should be used. I've tried various combinations but none seem to work. In my code I'm using sockets and pthreads but I dont think its really relevant to the problem, as I'm trying to set an alarm via a signal, which would halt all threads anyway, so I'll leave that code out for simplicity.
void handle_alarm(int sig){
printf("Printing Info\n");
}
int main(int argc, char**argv){
struct itimerval it_val;
signal(SIGALRM, handle_alarm);
it_val.it_value.tv_sec = 1;
it_val.it_value.tv_usec = 1000000;
it_val.it_interval = it_val.it_value;
setitimer(ITIMER_REAL, &it_val, NULL);
while(1){}
return 0;
}
It should simply print to the terminal every second but it does not. Can anyone give me any advice?