Find the answer to your Linux question:
Results 1 to 2 of 2
I am fedup with this program, someone please please help me. Why is the timer not executing? Code: #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #include <time.h> #include <pthread.h> ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    34

    Question [SOLVED] Someone please helpppp: GNU C


    I am fedup with this program, someone please please help me.
    Why is the timer not executing?

    Code:
    #include <stdlib.h>
    #include <unistd.h>
    #include <stdio.h>
    #include <signal.h>
    #include <time.h>
    #include <pthread.h>
    
    
    void func(union sigval sv)
    {
     printf("iNSIDE FUNC");
    
    }
    
    int main()
    
    {
    
     int i;
     timer_t timerid;
     struct sigevent sevp;  // argument to timer_create
     struct itimerspec its; // argument to timer_gettime
    
     sevp.sigev_notify=SIGEV_THREAD;
     sevp.sigev_signo=SIGRTMIN;
     sevp.sigev_value.sival_ptr=&timerid;
     sevp.sigev_notify_function=(void*)func;
    
     /* Setting timer interval */
     its.it_interval.tv_sec=1;
     its.it_interval.tv_nsec=0;
    
     /* Setting timer expration */
    
      its.it_value.tv_sec=1;  // First expiry after 1 sec
      its.it_value.tv_nsec=0;
    
     if(timer_create(CLOCK_REALTIME,&sevp,&timerid)==-1)
      {
       perror("create_timer failed");
      exit(1);
      }
     else {
      printf("create_timer succeeded, timer_ID: %u",timerid);
      }
     if(timer_settime(timerid,0,&its,NULL)==-1)
      {
       perror("settimer failed");
       exit(1);
      }
    
     for(i=0;i<10;i++)
      {
       printf("i = %d\n",i);
       sleep(1);
      }
    }
    Last edited by kingsmasher1; 03-03-2011 at 10:11 AM.

  2. #2
    Just Joined!
    Join Date
    Dec 2010
    Posts
    34
    The problem is solved, the code works after setting a memset:

    memset (&sevp, 0, sizeof (struct sigevent));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •