c - select interrupted system call -


i creating timer runs approximately every second , waiting key pressed (which not doing). while running shows:

select : interrupted system call  select : interrupted system call  select : interrupted system call  select : interrupted system call  

can tell me why happening:

struct sigaction s1; static timer_t tid3;     sigfillset(&s1.sa_mask); s1.sa_flags = sa_siginfo; s1.sa_sigaction = signalhandler; if (sigaction(sigu, &s1, null) == -1)  {   perror("s1 failed");   exit( exit_failure ); } printf("\ntimer %d setting \n",timeridentity);     tid3=settimer(sigu, 1000, 1);  // ---------- set timer values ------------------- static struct sigevent sigev; static timer_t tid; static struct itimerspec itval; static struct itimerspec oitval; sigev.sigev_notify = sigev_signal; sigev.sigev_signo = signo; sigev.sigev_value.sival_ptr = &tid;  if (timer_create(clock_realtime, &sigev, &tid) == 0)  {     itval.it_value.tv_sec = sec/1000;     itval.it_value.tv_nsec = (long)(sec % 1000) * (1000000l);     //itval.it_value.tv_nsec = 0;      if (mode == 1)      {         itval.it_interval.tv_sec = itval.it_value.tv_sec;         itval.it_interval.tv_nsec = itval.it_value.tv_nsec;     }     if (timer_settime(tid, 0, &itval, null) == 0)      {         printf("timer_settime \n");     }     else     {         perror("time_settime error!");     } }  //---------------- signal handler ----------------   void signalhandler(int signo, siginfo_t* info, void* context) {     else if (signo == sigu) // keypad being pressed    {       calltimer3function();    } 

}

//-----------------calltimer3function------------------------    unsigned char key5_debounce=0,key5_debounce_count=0; calltimer3function() {     if(!key5_debounce)    {        if((gpioread(input_sw5)==0))        {           key5_debounce=1;        }    }    if(key5_debounce)    {        if((gpioread(input_sw5)==0))        {           key5_debounce_count++;        }        else        key5_debounce=0;          if(key5_debounce_count>=key_debounce)         {            printf("key5 pressed\n");            extr_count=1;            printf("\ndisplay menu called");            display_menu();            key5_debounce=0;           key5_debounce_count=0;         }     } } 

it may worth mentioning 2 things:

  1. blocking functions such select, read, etc.. interrupted signals. may set sa_restart flag when calling sigaction. man signal(7):

if signal handler invoked while system call or library function call blocked, either:

  • the call automatically restarted after signal handler returns; or
  • the call fails error eintr.

which of these 2 behaviors occurs depends on interface , whether or not signal handler established using sa_restart flag (see sigaction(2)). details vary across unix systems; below, details linux.

  1. in signal handler should call async signal safe functions. or use the self-pipe trick avoid doing in signal handler @ all.

alternatively, there way have timers without using timer_create , timerfd_create. select accepts timeout argument can used specify time till next timer expiry. then, select returns 0 if timeout occurred. method applies other event demultiplexing apis, such poll , epoll.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -