#include<stdio.h>
int h;
void hijos2 (int Nv2, int Nh2){
switch (fork()) {
case -1:
printf("Error\n");
break;
case 0:
printf("Es el hijo numero %d cuyo padre es %d, HIJOS2 coordendas %d, %d\n", getpid(), getppid(),Nv2, Nh2);
// fflush(stdout);
break;
default:
if ((Nh2-h) > 0)
hijos2(Nv2, Nh2-h);
break;
}
return;
}
void hijos (int Nv, int Nh) {
switch (fork()) {
case -1:
printf("Error\n");
break;
case 0:
printf("Es el hijo numero %d cuyo padre es %d. HIJOS, coordenadas %d, %d\n", getpid(), getppid(), Nv, Nh);
//fflush(stdout);
break;
default:
if ((Nh-h) > 0)
hijos2(Nv,Nh-h);
if ((Nv-h) > 0)
hijos(Nv-h, Nh);
break;
}
return;
}
main (){
int cas, temp;
printf("Introduzca el numero de casillas, y el divisor: \n");
scanf("%d%d", &cas, &h);
hijos(cas, cas);
}