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

void Message();

main() {

  int pid;
  int i;

  pid = fork();
  if (pid == -1) {
    printf("Fork error!\n");
    exit(1);
  }

  signal(SIGUSR1, Message); 

  if (pid != 0) { /* parent */
    printf("Parent waiting...\n");
    sleep(5);
    kill(pid, SIGUSR1);		/* tell child to stop */
  } else { /* child */
    while (1) {
      i++;
      printf("%d\n", i);
    }
  }

}


void Message()
{
   fprintf(stderr, "Time to stop.\n");
   exit(0);
}

