c - Stop or Start setitimer -
i have set timer have 1 small issue, whenever alarm expires , catch_alarm function called, the timer stops , restarts when in returns main function . need perform benchmarks (packets received , send different interfaces) not include time takes processing not reflect true rx , tx rates accurately
the code sample shown:
#include <signal.h> #include <stdio.h> #include <string.h> #include <sys/time.h> void catch_alarm (int sig) { //stop timer here printf("calling interrupt now\n"); sleep(1); signal (sig, catch_alarm); //start here again } /*void waste (void) { printf("hello 1\n"); while(1) { printf("hello 2\n"); } printf("hello 3\n"); }*/ struct itimerval old; struct itimerval new; int main(void) { signal (sigalrm, catch_alarm); new.it_interval.tv_sec = 1; new.it_interval.tv_usec = 500000; new.it_value.tv_sec = 1; new.it_value.tv_usec = 500000; old.it_interval.tv_sec = 0; old.it_interval.tv_usec = 0; old.it_value.tv_sec = 0; old.it_value.tv_sec = 0; if (setitimer (itimer_real, &new, &old) < 0) printf("timer init failed\n"); else printf("timer init succeeded\n"); while(1) { printf("in while loop\n"); //sleep(10); //waste(); printf("resuming sleep\n"); } return 0; }
p.s: sigaction better suited here, if so, how ?
Comments
Post a Comment