Simple Signals - C programming and alarm function

后端 未结 4 1586
挽巷
挽巷 2020-12-01 04:39
#include  
#include  


void  ALARMhandler(int sig)
{
  signal(SIGALRM, SIG_IGN);          /* ignore this signal       */
  printf(\"H         


        
4条回答
  •  被撕碎了的回忆
    2020-12-01 05:13

    You are not installing the signal handler first.
    You need to tell the system that you want to handle the signal before actually receiving it, so you need to call signal() from main before the signal comes.

    int main(int argc, char *argv[])
    {
      signal(SIGALRM, ALARMhandler);     /* install the handler    */
      alarm(2);                     /* set alarm clock          */
      while (1);
    }
    

提交回复
热议问题