#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h> // for waitpid()
#include <sys/wait.h> //for waitpid()
#include <signal.h>

#define CHILD_COUNT 3

int counter=0;

void sig10_handler(void)
{
   //printf("\nSonlaniyorum :: %d", getpid());
}

int main(void)
{ int f=1, i;
  int children[CHILD_COUNT]; 

  for (i=0; i<CHILD_COUNT; i++)
  {
    if (f>0)
      f=fork();
      if (f==-1)
      {
        printf("fork error....\n");
	     exit(1);
      }	
      if (f==0)
        break;
      else
        children[i]=f;		
  }
  if (f>0)
  {
    
    waitpid(children[CHILD_COUNT-1], NULL, 0);
    printf("Parent process terminating...\n");
  }
  else
  {
    signal(10,  (sighandler_t) sig10_handler);
    printf("\n %d. child pid = %d\n",i, getpid());
    pause();
    sleep(i); 
    printf("\n Child %d: Terminating....\n",getpid());
  } 
  return(0); 
}

