/* A program that receives and handles signals
   Written by Andre M. Maier, dhbw@andre-maier.com */

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

void signal_handler(int signo)
{
   printf("Received Signal No. %d\n", signo);
}

int main(int argc, char** argv)
{
   printf("PID is %d\n",getpid());
   if(signal(SIGINT, signal_handler)==SIG_ERR)
      printf("Cannot catch SIGINT\n");
   if(signal(SIGTERM, signal_handler)==SIG_ERR)
      printf("Cannot catch SIGTERM\n");
   if(signal(SIGUSR1, signal_handler)==SIG_ERR)
      printf("Cannot catch SIGUSR1\n");
   if(signal(SIGSTOP, signal_handler)==SIG_ERR)
      printf("Cannot catch SIGSTOP\n");
   if(signal(SIGKILL, signal_handler)==SIG_ERR)
      printf("Cannot catch SIGKILL\n");
   while(1)
      sleep(1000);
   return 0;
}
