title: Which thread handles the signal?
body: <p>I have 2 threads(thread1 and thread2). And I have signal disposition for <code>SIGINT</code>. Whenever <code>SIGINT</code> occurs thread 2 should handle the signal. For that I wrote below program</p>
  
  <pre><code>void sig_hand(int no)                  //signal handler
  {
      printf("handler executing...\n");
      getchar();
  }
  
  void* thread1(void *arg1)              //thread1 
  {
      while(1) {
              printf("thread1 active\n");
              sleep(1);
      }
  }
  
  void * thread2(void * arg2)           //thread2
  {
      signal(2, sig_hand);
      while(1) {
      printf("thread2 active\n");
      sleep(3);
      }
  }
  
  int main()
  {
      pthread_t t1;
      pthread_t t1;
  
      pthread_create(&amp;t1, NULL, thread1, NULL);
      pthread_create(&amp;t2, NULL, thread2, NULL);
      while(1);
  }
  </code></pre>
  
  <p>I compiled and and run the program. for every 1 second "thread1 active" is printing and for every 3 seconds "thread2 active" is printing.</p>
  
  <p>Now I generated <code>SIGINT</code>. But its printing "thread1 active" and "thread2 active" messages like above. Again I generated <code>SIGINT</code>, now for every 3 seconds only "thread2 active" message is printing. Again I generated <code>SIGINT</code>, now all threads are blocked.</p>
  
  <p>So I understood, for first time main thread executing signal handler. For second time thread1 executing handler and lastly thread2 executing signal handler.</p>
  
  <p>How I can write the code like whenever signal occurs, only thread2 have to execute my signal handler?</p>