1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <stdio.h>
#include <unistd.h>
int main(){
int pid;
int pidd;
int status;
int i;
switch(pid=fork()){
case -1: printf("Error lors de la création du proc fils");
exit(0);
case 0: printf("Je suis le premier fils %d de pere %d\n", getpid(), getppid());
i = 0;
do{
pidd = fork();
switch(pidd){
case -1:
printf("Error");
exit(0);
case 0:
printf("Je suis le fils n°%d , %d de pere %d\n", i, getpid(), getppid();
exit(0);
default:
wait(NULL);
printf("Je suis le père\n");
}
i++;
}while(i <10);
printf("Je sors de ma boucle\n");
exit(0);
default: wait(&status);
printf("Je suis le premier père\n");
printf("Je suis le premier fils %d de pere %d\n", getpid(), getppid());
exit(128);
}
return 0;
} |
Partager