/*------------------------------------------------------------------*/ /* testitimer.c */ /* The setitimer function. */ /* Author: Bob Dondero */ /*------------------------------------------------------------------*/ #define _GNU_SOURCE #include #include #include #include #include /*------------------------------------------------------------------*/ static void myHandler(int iSig) /* This function is intended to be a handler for signals of various types. Print iSig to stdout. */ { printf("In myHandler with argument %d\n", iSig); } /*------------------------------------------------------------------*/ int main(void) /* Illustrate the setitimer() function. */ { int iRet; void (*pfRet)(int); struct itimerval sTimer; pfRet = signal(SIGPROF, myHandler); assert(pfRet != SIG_ERR); /* Create an interval timer to generate a SIGPROF signal after A seconds and B microseconds of virtual time. Thereafter repeatedly generate a SIGPROF signal at C second, D microsecond intervals of virtual time. */ sTimer.it_value.tv_sec = 1; /* A */ sTimer.it_value.tv_usec = 0; /* B */ sTimer.it_interval.tv_sec = 1; /* C */ sTimer.it_interval.tv_usec = 0; /* D */ iRet = setitimer(ITIMER_PROF, &sTimer, NULL); assert(iRet != -1); printf("Entering an infinite loop\n"); for (;;) ; return 0; }