Why we call Signal Handler twice?

Viewed 2025

I am a novice to signal handling using c language. I am analyzing below signal handling code which extracted from specific resource.

Here is that code .

    #include <stdio.h>
    #include <signal.h>

    void intproc();
    void quitproc();

    main()
    {
      int i;

      signal(SIGINT,intproc);
      signal(SIGQUIT,quitproc);

      printf("Ctrl+c is disabled. Use ctrl+\\ to quit\n");

      for (i=0;;i++) {
        printf("In an infinite loop...\n"); 
        sleep(200);
        }
    }


    void intproc()
    {
      signal(SIGINT,intproc);
      printf("You have pressed ctrl+c.\n");
    }

    void quitproc()
    { signal(SIGQUIT,intproc);
      printf("You have pressed ctrl+\\. Now the program quits.\n");
      exit(0);
    }

what I want to know is why we call again Signal handler "(SIGINT,intproc)" inside intproc() function ?

I tried to run this code without that signal handler within that function ,and its also working .

2 Answers
Related