title: How to block signals in C?
body: <p>I'm trying to create a program that blocks the signal SIGUSR1 and the it unblocks the signal.
  In the middle I want to see that the signal is blocked using <code>sigpending</code>. But it always says that the signal isn't blocked, and I can use the signal when it's supposed to be blocked.
  This is the code that I have.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;signal.h&gt;
  
  static void signals(int signaln) 
  {
    switch (signaln) {
    case SIGUSR1:
      printf("Signal SIGUSR1\n"); break;
    }
    return; 
  }
  main()
  {
    sigset_t set,set2;
    struct sigaction sigs;
    sigs.sa_handler = signals;
    sigemptyset(&amp;sigs.sa_mask);
    sigs.sa_flags=SA_ONESHOT;
    sigaction(SIGUSR1, &amp;sigs,0);
    sigemptyset(&amp;set);
    sigemptyset(&amp;set2);
    sigaddset(&amp;set,SIGUSR1);
    if(sigprocmask(SIG_BLOCK, &amp;set, NULL)==0){
      printf("Blocking SISGUSR1...\n");
    }
    sigpending(&amp;set2);
    if (sigismember(&amp;set2,SIGUSR1)==1)
    {
      printf("The signal is blocked\n");  //it should print this
    }
    wait(2);
    kill(getpid(),SIGUSR1); //the signal shouldn't work
    wait(2);
    if(sigprocmask(SIG_UNBLOCK, &amp;set, NULL)==0){
      printf("Unblocking SIGUSR1\n");
    }
  }
  </code></pre>
  
  <p>Could anyone help me?</p>