Probleme avec cet énoncé .

Fermé
daryun - Modifié le 4 nov. 2019 à 12:49
daryun Messages postés 1 Date d'inscription lundi 4 novembre 2019 Statut Membre Dernière intervention 4 novembre 2019 - 4 nov. 2019 à 13:28
Bonjour;

On a : pere a 3 fils T S T et chaque fils a un fils T(E) S(T) et T(P).



Synchronisez entre les différents processus pour avoir l’affichage : Père : TEST TP en utilisant la fonction wait(0) et exit(0).

mon programme affiche Pere:TESTTEST TP TP.

2 réponses

bendrop Messages postés 12484 Date d'inscription jeudi 30 juin 2005 Statut Contributeur Dernière intervention 23 avril 2024 8 226
4 nov. 2019 à 12:40
0
merci
voila mon code source;

#include <stdio.h> 
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{ 
  pid_t pid;
  

  if((pid=fork())==0)
  {
    printf("T");
    fork();
    printf("E");
    exit(0);
  }
  wait(0);  
  if((pid=fork())==0)
  {
    printf("S");
    fork();
    printf("T");
    exit(0);
  }
  wait(0);
  if((pid=fork())==0)
  {
    printf(" T");
    fork();
    printf("P\n");
    exit(0);
  }
  wait(0);
  
  printf("pere:");
  exit(0);
  


return 0;
}
0
bendrop Messages postés 12484 Date d'inscription jeudi 30 juin 2005 Statut Contributeur Dernière intervention 23 avril 2024 8 226
4 nov. 2019 à 12:56
0
daryun Messages postés 1 Date d'inscription lundi 4 novembre 2019 Statut Membre Dernière intervention 4 novembre 2019 > bendrop Messages postés 12484 Date d'inscription jeudi 30 juin 2005 Statut Contributeur Dernière intervention 23 avril 2024
4 nov. 2019 à 13:28
#include <stdio.h> 
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{ 
  pid_t pid;
  

  if((pid=fork())==0)
  {
    printf("T");
    fork();
    printf("E");
    exit(0);
  }
  wait(0);  
  if((pid=fork())==0)
  {
    printf("S");
    fork();
    printf("T");
    exit(0);
  }
  wait(0);
  if((pid=fork())==0)
  {
    printf(" T");
    fork();
    printf("P\n");
    exit(0);
  }
  wait(0);
  
  printf("pere:");
  exit(0);
  


return 0;
}
0