Thenks so much i will check your recommendations. Instead i have created a simply code but i have problems with the printf..any idea where is the problem? Here i post the code:
Thanks again!!
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
main(){
pid_t pid;
pid_t spid;
pid_t sspid;
int i, n=20;
for (i=0; i<n; i++) {
pid=fork();
if (pid == 0){
// Son process
if(i%2 == 0){
//Son process && even
spid = fork();
if (spid == 0){
// Grand son process
if(i%3 == 0){
sspid = fork();
if (sspid == 0){
// Great grand son process
} else {
// Grand son process
}
}
}
}
break; // to avoid continuing the for in the child processes
} else {
// Main process
}
}
printf("The father in the process %d is %d", getpid(),getppid());
}