#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

void generic_handler(int sig) {
  fprintf(stdout,"Process %d got signal %d\n",getpid(),sig);
  return;
}

int main(int argc, char **argv)
{
  pid_t pid;

  pid = fork();

  if (pid < 0) {
    fprintf(stderr,"Error: can't fork a process\n");
    perror("fork()");
    exit(1);
  } else if (pid) { // I am the parent
    while (1) {
      sleep(1);
      if (kill(pid, SIGINT)) {
        perror("kill()");
      }
    }
  } else {
    fprintf(stdout,"I am the child and my pid is %d\n",getpid());
    if (signal(SIGINT, generic_handler) == SIG_ERR) {
      perror("signal()");
    }
    while (1) ; // infinite loop
  }
}

