Probleme avec cet énoncé .

daryun -  
daryun Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -
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 12729 Date d'inscription   Statut Contributeur Dernière intervention   8 381
 
0
daryun
 
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 12729 Date d'inscription   Statut Contributeur Dernière intervention   8 381
 
0
daryun Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   > bendrop Messages postés 12729 Date d'inscription   Statut Contributeur Dernière intervention  
 
#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