le programme doit créer des processus en utilisant la fonction fork() et a chaque création afficher le pid du processus créer et le pid du processus parent.
les créations doivent être faites selon l'ordre généalogique suivante : P1 , P2 P3 P4 créer à partir P1 et P4 P5 créer à partir de P4
mon code sources pour la création des processus P2, P3, et P4 à partir de P1 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char const *argv[]) { printf("pid P1 : %d\n", getpid());// Affichage du pid de P1 pid_t P2 = fork(); // création de P2 if(P2 == 0) { printf("pid P2 : %d, pid parent P1 : %d\n", getpid(), getppid()); } pid_t P3 = fork(); if(P3 == 0) { printf("pid P3 : %d, pid parent P1 : %d\n", getpid(), getppid()); } pid_t P4 = fork(); if(P4 == 0) { printf("pid P4 : %d, pid parent P1 : %d\n", getpid(), getppid()); } return 0; }
voila ce que j'ai après exécution :
maintenat j'arrive pas à comprendre pourquoi il y'a d'autre affichage après l'affichage du PID de P2, P3, P4 et celui de leur parent P1. Comment je pourrai résoudre ce problème.pid P1 : 12544
pid P2 : 12545 pid parent P1 : 12544
pid P3 : 12546 pid parent P1 : 12544
pid P4 : 12547 pid parent P1 : 12544
pid P3 : 12548 pid parent P1 : 12545
pid P4 : 12549 pid parent P1 : 12546
pid P4 : 12550 pid parent P1 : 12545
pid P4 : 12551 pid parent P1 : 12548
Aidez moi svp
Partager