/* sigill.c - Process sets a handler for SIGILL, and suspends until any 
 * signal is received. If SIGILL is received the handler
 * is executed; for all other signals the handler is not executed.
 * You can run this program with "% a.out &". The program prints
 * its own processid. Then you can send a SIGILL signal to it with 
 *             % kill -ILL processid
 * Sending any other signal will not invoke the handler and will have
 * the usual behavior: will be ignored or will terminate the process.
 */

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

void handler(int a ); 

int main() {
  sigset_t  zeromask;
  struct sigaction  action, old_action;
  
  /* Block all signals when executing handler */
  sigfillset(&action.sa_mask); 
  action.sa_handler = handler;
  action.sa_flags = 0;
  if (sigaction(SIGILL,&action,&old_action)==-1) 
    perror( "sigaction");
  /* wait for any signal */
  sigemptyset(&zeromask);
  sigsuspend(&zeromask); 
  printf("After signal is received and perhaps handled\n");
  return 0;
}

void handler(int a){
  printf("\ncaught signal %d\n", a);
};

