//	fork.c	
// Szablon programu prezentujacego tworzenie procesow

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


int main()
{ 
  int f;
  char buf[100];
   
   
  
  if ((f=fork())==0)   {
     execl("context","1",NULL);
  }
  else 
  if ((f=fork())==0)   {
    if ((f=fork())==0)   {
     execl("context","22",NULL);
    }
     execl("context","2",NULL);
  }
  if ((f=fork())==0)   {
  	  if ((f=fork())==0)   {
    	  if ((f=fork())==0)   {
         execl("context","333",NULL);
        }
  	    execl("context","33",NULL);
  	  }
     execl("context","3",NULL);
  }
  if ((f=fork())==0)   {
    if ((f=fork())==0)   {
     execl("context","41",NULL);
    }  
    if ((f=fork())==0)   {
     if ((f=fork())==0)   {
      execl("context","421",NULL);
     }  
     execl("context","42",NULL);
    }  
	if ((f=fork())==0)   {
     execl("context","43",NULL);
    }      
     execl("context","4",NULL);
  }  
  else {   
  if (f == -1) { 
           sprintf(buf, "\n%d Blad powolania potomnego 1\n", getpid());
           write(STDOUT_FILENO, buf, strlen(buf));
           pause();
           exit(1); }     
        else { 
           sprintf(buf,"jestem macierzysty: %d\n", getpid());
           write(STDOUT_FILENO, buf, strlen(buf));
           pause();
           exit(0);  }
   }
  }

