// Source https://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/

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

void sig_handler(int signo) {
  if (signo == SIGUSR1)
    printf("received USR1\n"); 
  if (signo == SIGUSR2)
    printf("received USR2\n"); }

int main(void) {
  if (signal(SIGUSR1, sig_handler) == SIG_ERR)
      printf("\ncan't catch USR1\n");
  if (signal(SIGUSR2, sig_handler) == SIG_ERR)
      printf("\ncan't catch USR2\n");      
  // A long long wait so that we can easily 
  // issue a signal to this process
  while(1) 
    sleep(1);
  return 0; }
  
  
  
  
