I have this C++ program. It has a simple for loop which prints numbers from 1 to 20. Between this, execution, the timer expires multiple times, and each time it expires, it should print an output from signal handler.
Unfortunately i am not getting this output. And it is just simply printing the numbers from 1 to 20. Can someone please help me?
Thanks in advance

#include #include #include #include #include #define CLOCKID CLOCK_REALTIME#define SIG SIGRTMIN#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \} while (0)#include using namespace std;static int flag=0;class timer{static voidhandler(int sig) { printf("Caught signal %d\n", sig); ::flag=1; signal(sig, handler);}public:void timer_func(){timer_t timerid;struct sigevent sev;struct itimerspec its;long long freq_nanosecs=1; // The timer frequency in nanosecssigset_t mask;struct sigaction sa;/* Establish handler for timer signal */printf("Establishing handler for signal %d\n", SIG);sa.sa_flags = SA_RESETHAND;sa.sa_handler = handler; /* Create the timer */ sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = SIG; sev.sigev_value.sival_ptr = &timerid; if (timer_create(CLOCKID, &sev, &timerid) == -1) errExit("timer_create"); printf("timer ID is 0x%lx\n", (long) timerid); /* Start the timer */ its.it_value.tv_sec = freq_nanosecs / 1000000000; its.it_value.tv_nsec = freq_nanosecs % 1000000000; its.it_interval.tv_sec = its.it_value.tv_sec; its.it_interval.tv_nsec = its.it_value.tv_nsec; if (timer_settime(timerid, 0, &its, NULL) == -1) errExit("timer_settime"); } }; int main() { timer ob; ob.timer_func(); for(int i=0; i