选择中断的系统调用 [英] select interrupted system call

查看:89
本文介绍了选择中断的系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个大约每秒运行一次的计时器,它正在等待按下一个键(我没有这样做)。当它运行时显示:



I am creating a timer which runs approximately every second and which is waiting for a key to be pressed (which i am not doing). While it is running it shows:

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







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 is setting up \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) // for 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;
        }

   }
}

推荐答案

该消息表明打电话给 select()已被中断。但是你的代码片段没有包含对 select()的调用。



有很多问题和注释(除了我上面关于不完整处理函数的评论):



为什么你使用 sigfillset()时只处理特定信号?

最好使用 sigempty()并添加处理的信号。



什么是 SIGU

这不是标准信号。



信号处理程序应仅调用异步信号安全函数。请参见 man 7信号 [ ^ ]。 printf()不属于这些函数。当 display_menu()听到它的声音时,它肯定不会被信号处理程序调用。
The message indicates that a call to select() has been interrupted. But your code snippets did not contain a call to select().

There are a lot of questions and notes (besides my above comment about the incomplete handler function):

Why did you use sigfillset() when only handling specific signals?
It would be better to use sigempty() and add the signals that are handled.

What is SIGU?
It is not a standard signal.

A signal handler should call async-signal-safe functions only. See man 7 signal[^]. printf() does not belong to these functions. When display_menu() does what it sounds like, it should definitely not called by a signal handler.


这篇关于选择中断的系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆