#include <stdio.h>
#include <unistd.h> //for fork(), getpid(), sleep()
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h> //for wait()

int main (void)
{
  int f;

  f=fork();
    
  //printf("f:: %d \n", f);
  if (f==-1)
  {
    printf("Hata \n");
    exit(1);
  } 
  else if (f==0) /* cocuk */
  {
    printf("   Cocuk: Proses no: %d \n", getpid());
    sleep(1);
    printf("   Cocuk: Annemin no: %d \n", getppid());
    exit(0);
  }
  else
  {
    printf("Anne: Proses no: %d \n", getpid());
    printf("Anne: Cocugumun no: %d \n", f);
    printf("Anne: Annemin no: %d \n", getppid());
    wait(NULL); //Anne proses sonlanmak icin cocuk prosesleri bekliyor
    // wait() ile geri donen deger sonlanmis olan cocuk prosesin PID'sidir
    //printf(":: %d \n", wait(NULL));
    printf("Anne: Sonlaniyorum...\n");
    exit(0);
  }
  return (0);
}


