Вы находитесь на странице: 1из 6

INF3600+INF2610 Automne 2006

Partie 2 : Communication interprocessus


Exercice 1 :
Considérez N processus qui communiquent au moyen de tubes de communication non nommés
(unnamed pipe). Chaque processus partage deux tubes (un avec le processus de droite et un autre
avec le processus de gauche). Par exemple pour N=4, les processus communiquent selon le
schéma suivant :

P0 tub0 P1

tub3 tub1

P3 tub2 P2

1) Complétez le code ci-après de manière à implémenter cette architecture de communication


des N processus créés. L’entrée standard et la sortie standard de chaque processus Pi sont
redirigées vers les tubes appropriés. Par exemple, pour le processus P0, l’entrée et la sortie
standards deviennent respectivement les tubes tub3 et tub0.
#include ″EntetesNecessaires.h″
#define N 4
void proc( int ) ;
int main ( )
{ int i ;
for( i=0 ; i <N; i++)
if ( fork() ==0)
{ proc(i); exit(0); }
exit(0) ;
}
#include ″codedeproc″
Attention : Vous ne devez pas écrire le code de la fonction proc.
1
Exercice 2 :
On veut établir, en utilisant les tubes anonymes (pipes), une communication de type anneau
unidirectionnel entre trois processus fils. Pour ce faire, la sortie standard de l’un doit être
redirigée vers l’entrée standard d’un autre, selon le schéma suivant :

P3

P1

P2

Complétez le programme suivant en y ajoutant le code permettant de réaliser les redirections


nécessaires à la création d’un tel anneau.

/*0*/
int main ()
{
/*1*/
if (fork()) // création du premier processus
{
if(fork())
{
/*2*/
if(fork())
{ /*3*/
while (wait(NULL)>0);
/*4*/
} else
{ // processus P3
/*5*/
execlp(“program3”, “program3”,NULL);
/*6*/

2
}
} else
{ // processus P2
/*7*/
execlp(“program2”, “program2”,NULL);
/*8*/
}
} else
{ //processus P1
/*9*/
execlp(“program1”,”program1”, NULL);
/*10*/
}
/*11*/
}

Exercice 3 :

Écrivez le « main » d’un processus qui permet de simuler un pipe (‘|’). Ce code doit utiliser un
tube nommé et doit avoir exactement le même comportement qu’un pipe (‘|’) dans un shell.

Exemples :
bash$> my_pipe who wc –l ( equivaut à bash$> who | wc –l)
bash$> my_pipe ls grep “my_pipe” ( équivaut à bash$> ls | grep “my_pipe”)

Exercice 4 :

Considérez le programme suivant :


#include <unistd.h>
#include <signal.h>
#include <stdio.h>

void sigintP()
{/*1*/}
void sigalrm()
{/*2*/}

3
void sigintF()
{/*3*/}
void sigchld()
{
int status;
wait(&status);
exit(0);
}

int main(void)
{
signal(SIGCHLD, sigchld);
if (fork() == 0)
{
signal(SIGINT, sigintF);
while(1)
{
printf (“ici fils \n”);
sleep(1);
}
}
while(1)
{
signal(SIGINT, sigintP);
printf(“ici pere \n”);
sleep(1);
}
return 0;
}
Complétez le code précédent de manière à réaliser ces traitements :
1. Si l’utilisateur presse les touches Ctrl-C lorsque le programme s’exécute, les processus père et
fils ne se terminent pas immédiatement, mais après un délai de 5 secondes. Lorsque l’utilisateur
presse les touches Ctrl-C, le père affiche son identificateur (sans se terminer).
Indication: Ctrl-C doit déclencher un appel système alarm(5), qui envoie automatiquement le
signal SIGALRM après 5 secondes.
2. Dans quel ordre les processus père et fils se terminent? Expliquez.

Exercice 5 :

4
Considérez le programme suivant :

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define N 5
void gestion(){ /* traitement */ };

/*0*/
int main( )
{ pid_t pid[N];
int i;
/*1*/
for ( i=0; i<N;i++)
if ((pid[i]=fork())==0)
{ /* 2*/
execlp("traitement", "traitement", NULL);
exit(1);
}
/*3*/
gestion( );
return 0;
}

1- On veut faire communiquer le processus père avec ses fils au moyen de deux tubes anonymes
(pipes sans nom) selon le schéma suivant :

5
La sortie standard du père est redirigée vers le pipe1 qui devient l’entrée standard des fils. Les
sorties standards et erreurs des fils sont redirigées vers le pipe2.

Complétez le code de manière à établir ces canaux de communication (supposez que le fork
n’échoue jamais).

Exercice 6 :

On dispose d'une fonction F() d’une bibliothèque qui écrit une certaine quantité de données sur la
sortie standard (descripteur de fichier 1). On aimerait récupérer, en utilisant un pipe anonyme,
ces données pour les traiter.

#define Taille 1024


int main
{
char Data[Taille];
/*1*/
F ( );
/*2*/
utiliser_resultat (Data);
}

1. Insérez du code en amont et en aval de F( ) afin que tous les caractères émis par F( ) sur la
sortie standard soient récupérés dans Data. Vous pouvez utiliser des variables et appels
système supplémentaires, mais vous ne pouvez pas utiliser de fichiers ni de processus
supplémentaires.
2. Que se passe-t-il, si la taille des données émises par F dépasse celle de Data ?
3. Que se passe-t-il, si la taille des données émises par f dépasse celle du pipe ?
4. Proposez une deuxième version corrigeant ces problèmes. Pour ce faire, vous pouvez utiliser
un processus supplémentaire.

Вам также может понравиться

  • TP 3
    TP 3
    Документ5 страниц
    TP 3
    djalaluniv
    Оценок пока нет
  • TP 3 Système D'exploitation 2: Gestion Des Processus: Cours Donné Par
    TP 3 Système D'exploitation 2: Gestion Des Processus: Cours Donné Par
    Документ10 страниц
    TP 3 Système D'exploitation 2: Gestion Des Processus: Cours Donné Par
    Benkilani Rim
    Оценок пока нет
  • Cours TP GestionProcessus
    Cours TP GestionProcessus
    Документ7 страниц
    Cours TP GestionProcessus
    Achref Hjaiej
    Оценок пока нет
  • Fork Exercice
    Fork Exercice
    Документ3 страницы
    Fork Exercice
    nour hene
    Оценок пока нет
  • Processus Threads Corrige
    Processus Threads Corrige
    Документ8 страниц
    Processus Threads Corrige
    Rita Bernice Shimwe
    Оценок пока нет
  • Pipes
    Pipes
    Документ6 страниц
    Pipes
    laksondz
    Оценок пока нет
  • Mod3 Solutions
    Mod3 Solutions
    Документ10 страниц
    Mod3 Solutions
    Mohamed Sakly
    Оценок пока нет
  • TDSE 01 09 2019-Correction
    TDSE 01 09 2019-Correction
    Документ10 страниц
    TDSE 01 09 2019-Correction
    Haj
    Оценок пока нет
  • Chapitre 13
    Chapitre 13
    Документ8 страниц
    Chapitre 13
    Nossayba Darraz
    Оценок пока нет
  • Tdse Fork 09 2017
    Tdse Fork 09 2017
    Документ5 страниц
    Tdse Fork 09 2017
    Chehira Doghmen
    Оценок пока нет
  • Inf3600 Exos2 PDF
    Inf3600 Exos2 PDF
    Документ17 страниц
    Inf3600 Exos2 PDF
    BtissamBetty
    Оценок пока нет
  • Ch4 PDF
    Ch4 PDF
    Документ11 страниц
    Ch4 PDF
    Sarah Derriche
    Оценок пока нет
  • Int Pid - T Char Int: If Else (
    Int Pid - T Char Int: If Else (
    Документ5 страниц
    Int Pid - T Char Int: If Else (
    hafssa benaddi
    Оценок пока нет
  • TP2 Gestiondesprocess PDF
    TP2 Gestiondesprocess PDF
    Документ11 страниц
    TP2 Gestiondesprocess PDF
    feriel
    Оценок пока нет
  • TP02-Programmation Des Processus
    TP02-Programmation Des Processus
    Документ4 страницы
    TP02-Programmation Des Processus
    hayfa rajhi
    Оценок пока нет
  • TP3 Correction
    TP3 Correction
    Документ5 страниц
    TP3 Correction
    zakariae harime
    Оценок пока нет
  • Cpinf 3600 A05 V2
    Cpinf 3600 A05 V2
    Документ6 страниц
    Cpinf 3600 A05 V2
    I-r Belghouthi
    Оценок пока нет
  • Initiation PROCESS
    Initiation PROCESS
    Документ12 страниц
    Initiation PROCESS
    Merry M
    100% (1)
  • td2 Se
    td2 Se
    Документ3 страницы
    td2 Se
    ayadhibi08
    Оценок пока нет
  • TD 1 (2020)
    TD 1 (2020)
    Документ4 страницы
    TD 1 (2020)
    Abir Abdelmoumen
    Оценок пока нет
  • TD 1 (2020)
    TD 1 (2020)
    Документ4 страницы
    TD 1 (2020)
    Abir Abdelmoumen
    Оценок пока нет
  • Communication Entre Processus
    Communication Entre Processus
    Документ49 страниц
    Communication Entre Processus
    Rabiaa Moulay
    Оценок пока нет
  • CPINF2610 Hiver 2017 Et Corrige
    CPINF2610 Hiver 2017 Et Corrige
    Документ7 страниц
    CPINF2610 Hiver 2017 Et Corrige
    chahoub
    Оценок пока нет
  • Processus Threads
    Processus Threads
    Документ7 страниц
    Processus Threads
    fokam
    Оценок пока нет
  • TD N°4 Synchronisation Des Processus: Exercice 1
    TD N°4 Synchronisation Des Processus: Exercice 1
    Документ4 страницы
    TD N°4 Synchronisation Des Processus: Exercice 1
    ifaoui shatha
    Оценок пока нет
  • TP Processus
    TP Processus
    Документ6 страниц
    TP Processus
    MG
    Оценок пока нет
  • Chapitre 5 Communication Synchronisation Interprocessus Avec Langage C
    Chapitre 5 Communication Synchronisation Interprocessus Avec Langage C
    Документ27 страниц
    Chapitre 5 Communication Synchronisation Interprocessus Avec Langage C
    Christian Mbip
    Оценок пока нет
  • TP N°2 Systeme 2020 2021
    TP N°2 Systeme 2020 2021
    Документ6 страниц
    TP N°2 Systeme 2020 2021
    Hasnaoui D Nourine
    Оценок пока нет
  • Examen 1h Principes Des Systèmes D'exploitation - Unix/Linux
    Examen 1h Principes Des Systèmes D'exploitation - Unix/Linux
    Документ4 страницы
    Examen 1h Principes Des Systèmes D'exploitation - Unix/Linux
    Mai Anh Thư
    Оценок пока нет
  • Correction Controle SE-2016
    Correction Controle SE-2016
    Документ3 страницы
    Correction Controle SE-2016
    Ahmed Abed
    Оценок пока нет
  • Seii - TP N°4
    Seii - TP N°4
    Документ3 страницы
    Seii - TP N°4
    yaaddd
    Оценок пока нет
  • Tp5 Corrige
    Tp5 Corrige
    Документ6 страниц
    Tp5 Corrige
    amiemanel
    Оценок пока нет
  • Chap2 SEA
    Chap2 SEA
    Документ26 страниц
    Chap2 SEA
    Achref Hjaiej
    Оценок пока нет
  • CPINF2610 Aut 2017 Et Corrige
    CPINF2610 Aut 2017 Et Corrige
    Документ6 страниц
    CPINF2610 Aut 2017 Et Corrige
    chahoub
    Оценок пока нет
  • TP Appelsystème
    TP Appelsystème
    Документ2 страницы
    TP Appelsystème
    Med Aref
    Оценок пока нет
  • TP1 Corrige
    TP1 Corrige
    Документ13 страниц
    TP1 Corrige
    hafidcisco
    Оценок пока нет
  • Processus Et Parallélisme
    Processus Et Parallélisme
    Документ4 страницы
    Processus Et Parallélisme
    Ilyass
    Оценок пока нет
  • Seii - TP N°3
    Seii - TP N°3
    Документ2 страницы
    Seii - TP N°3
    yaaddd
    Оценок пока нет
  • Module: Systèmes D'exploitation: Fiche de Travaux Pratiques N° 2
    Module: Systèmes D'exploitation: Fiche de Travaux Pratiques N° 2
    Документ6 страниц
    Module: Systèmes D'exploitation: Fiche de Travaux Pratiques N° 2
    SSSA
    Оценок пока нет
  • TP1 Se2
    TP1 Se2
    Документ2 страницы
    TP1 Se2
    Djihene Babahenini
    Оценок пока нет
  • 04 tp2 Io Correction
    04 tp2 Io Correction
    Документ4 страницы
    04 tp2 Io Correction
    gfhv
    Оценок пока нет
  • Examen Théorie Systeme 2I Janvier 2011
    Examen Théorie Systeme 2I Janvier 2011
    Документ7 страниц
    Examen Théorie Systeme 2I Janvier 2011
    Cécile MceTv
    Оценок пока нет
  • 02 Tp1 Fork Exec Correction
    02 Tp1 Fork Exec Correction
    Документ5 страниц
    02 Tp1 Fork Exec Correction
    Santi Lopez
    Оценок пока нет
  • Les TPS
    Les TPS
    Документ4 страницы
    Les TPS
    hafsa ladhasse
    Оценок пока нет
  • TP4 Communication Inter Processus Correction
    TP4 Communication Inter Processus Correction
    Документ4 страницы
    TP4 Communication Inter Processus Correction
    amiemanel
    Оценок пока нет
  • 01 Td1 Fork Enonce
    01 Td1 Fork Enonce
    Документ3 страницы
    01 Td1 Fork Enonce
    brahimjihad
    Оценок пока нет
  • Chapitre - 2 - Création - Manipulation Des Processus - ASEDS PDF
    Chapitre - 2 - Création - Manipulation Des Processus - ASEDS PDF
    Документ22 страницы
    Chapitre - 2 - Création - Manipulation Des Processus - ASEDS PDF
    Imad EL IDRISSI
    Оценок пока нет
  • Processus Exercice 1 PDF
    Processus Exercice 1 PDF
    Документ6 страниц
    Processus Exercice 1 PDF
    Meher Guesmi
    Оценок пока нет
  • Signaux
    Signaux
    Документ3 страницы
    Signaux
    foreveroussama_012444
    Оценок пока нет
  • Correction TP3 Systeme Exploitation 2
    Correction TP3 Systeme Exploitation 2
    Документ15 страниц
    Correction TP3 Systeme Exploitation 2
    eya drihmi
    Оценок пока нет
  • TP4 Gestion Proc
    TP4 Gestion Proc
    Документ3 страницы
    TP4 Gestion Proc
    wided1657
    Оценок пока нет
  • TP 06 07
    TP 06 07
    Документ9 страниц
    TP 06 07
    olfaFakh
    Оценок пока нет
  • TP 1: Échantillonnage D'un Signal D'entrée
    TP 1: Échantillonnage D'un Signal D'entrée
    Документ8 страниц
    TP 1: Échantillonnage D'un Signal D'entrée
    Khawla Miloudi
    Оценок пока нет
  • Threads
    Threads
    Документ6 страниц
    Threads
    Ines Tlili
    100% (1)
  • Chap5 PDF
    Chap5 PDF
    Документ28 страниц
    Chap5 PDF
    Djongang Darylle
    Оценок пока нет
  • Correction Examen SEA1-S2
    Correction Examen SEA1-S2
    Документ4 страницы
    Correction Examen SEA1-S2
    Olfa SELMI
    Оценок пока нет
  • Acadc TP4-2020
    Acadc TP4-2020
    Документ3 страницы
    Acadc TP4-2020
    lisa mesbahi
    Оценок пока нет
  • tp3 Corr
    tp3 Corr
    Документ5 страниц
    tp3 Corr
    Hajar Smile
    Оценок пока нет
  • Python pour Débutants : Guide Complet pour Apprendre la Programmation Pas à Pas
    Python pour Débutants : Guide Complet pour Apprendre la Programmation Pas à Pas
    От Everand
    Python pour Débutants : Guide Complet pour Apprendre la Programmation Pas à Pas
    Оценок пока нет
  • LINUX Le Guide des commandes
    LINUX Le Guide des commandes
    От Everand
    LINUX Le Guide des commandes
    Оценок пока нет
  • Interblocage PDF
    Interblocage PDF
    Документ5 страниц
    Interblocage PDF
    Hmida
    Оценок пока нет
  • Chap 1
    Chap 1
    Документ19 страниц
    Chap 1
    Houty Karim
    Оценок пока нет
  • CH 9 Mem Vir
    CH 9 Mem Vir
    Документ29 страниц
    CH 9 Mem Vir
    Hmida
    Оценок пока нет
  • Annexes
    Annexes
    Документ20 страниц
    Annexes
    Hmida
    Оценок пока нет
  • Chap 2
    Chap 2
    Документ45 страниц
    Chap 2
    satmania
    Оценок пока нет
  • Ch8INF3600 PDF
    Ch8INF3600 PDF
    Документ17 страниц
    Ch8INF3600 PDF
    Hmida
    Оценок пока нет
  • CH 10 INF3600
    CH 10 INF3600
    Документ29 страниц
    CH 10 INF3600
    Hmida
    Оценок пока нет
  • CH 8 INF3600
    CH 8 INF3600
    Документ17 страниц
    CH 8 INF3600
    Hmida
    Оценок пока нет
  • CH 4 INF3600
    CH 4 INF3600
    Документ37 страниц
    CH 4 INF3600
    Hmida
    Оценок пока нет
  • CH 6 INF3600
    CH 6 INF3600
    Документ17 страниц
    CH 6 INF3600
    Hmida
    Оценок пока нет
  • Aaaaafggg
    Aaaaafggg
    Документ22 страницы
    Aaaaafggg
    capodelcapo
    Оценок пока нет
  • Ch5INF3600 PDF
    Ch5INF3600 PDF
    Документ33 страницы
    Ch5INF3600 PDF
    Hmida
    Оценок пока нет
  • CH 3 INF3600
    CH 3 INF3600
    Документ20 страниц
    CH 3 INF3600
    Hmida
    Оценок пока нет
  • CH 2 INF3600
    CH 2 INF3600
    Документ19 страниц
    CH 2 INF3600
    Hmida
    Оценок пока нет
  • CH 1 INF3600
    CH 1 INF3600
    Документ35 страниц
    CH 1 INF3600
    Hmida
    Оценок пока нет
  • Gestion Des Processus
    Gestion Des Processus
    Документ159 страниц
    Gestion Des Processus
    Safae Belkhyr
    100% (1)
  • Travaux Pratique 09
    Travaux Pratique 09
    Документ3 страницы
    Travaux Pratique 09
    Ahmed Fawzi
    Оценок пока нет
  • Chapitre - 2 - Création - Manipulation Des Processus - ASEDS PDF
    Chapitre - 2 - Création - Manipulation Des Processus - ASEDS PDF
    Документ22 страницы
    Chapitre - 2 - Création - Manipulation Des Processus - ASEDS PDF
    Imad EL IDRISSI
    Оценок пока нет
  • Correction TP3 Systeme Exploitation 2
    Correction TP3 Systeme Exploitation 2
    Документ15 страниц
    Correction TP3 Systeme Exploitation 2
    eya drihmi
    Оценок пока нет
  • Sys Exploitation
    Sys Exploitation
    Документ110 страниц
    Sys Exploitation
    Wail Choukhairi
    Оценок пока нет
  • Systeme D'Exploitation: Processus & Synchronisation (Programmation Système)
    Systeme D'Exploitation: Processus & Synchronisation (Programmation Système)
    Документ12 страниц
    Systeme D'Exploitation: Processus & Synchronisation (Programmation Système)
    Asmae Amakrane
    Оценок пока нет
  • Chapitre 5 Communication Synchronisation Interprocessus Avec Langage C
    Chapitre 5 Communication Synchronisation Interprocessus Avec Langage C
    Документ27 страниц
    Chapitre 5 Communication Synchronisation Interprocessus Avec Langage C
    Christian Mbip
    Оценок пока нет
  • TP1-Gestion Des Processus
    TP1-Gestion Des Processus
    Документ10 страниц
    TP1-Gestion Des Processus
    Elyes
    100% (1)
  • 1 Processus
    1 Processus
    Документ45 страниц
    1 Processus
    Hossam Eddin
    Оценок пока нет
  • ED2 Corrige-2 PDF
    ED2 Corrige-2 PDF
    Документ3 страницы
    ED2 Corrige-2 PDF
    Wided Touhami
    Оценок пока нет
  • Programmation Systeme Part 3
    Programmation Systeme Part 3
    Документ50 страниц
    Programmation Systeme Part 3
    yann chebu
    Оценок пока нет
  • Exam Control
    Exam Control
    Документ24 страницы
    Exam Control
    Mariam Minouari
    Оценок пока нет
  • TP3 GestionCPU
    TP3 GestionCPU
    Документ3 страницы
    TP3 GestionCPU
    zaki
    Оценок пока нет
  • TD1 Correction
    TD1 Correction
    Документ2 страницы
    TD1 Correction
    pojef57126
    Оценок пока нет
  • Chapitre1 Processus
    Chapitre1 Processus
    Документ20 страниц
    Chapitre1 Processus
    Fatma Chaari
    Оценок пока нет
  • Pipes PDF
    Pipes PDF
    Документ6 страниц
    Pipes PDF
    Hmida
    Оценок пока нет
  • La Programmation Système en C Sous Unix
    La Programmation Système en C Sous Unix
    Документ58 страниц
    La Programmation Système en C Sous Unix
    Fadhul Djirame
    Оценок пока нет
  • 01 td1 Fork Correction
    01 td1 Fork Correction
    Документ6 страниц
    01 td1 Fork Correction
    Aymane As
    Оценок пока нет
  • Chap 3
    Chap 3
    Документ80 страниц
    Chap 3
    safe selmi
    Оценок пока нет
  • Mps
    Mps
    Документ214 страниц
    Mps
    Housem Eddine Benjemaa
    Оценок пока нет
  • Ae 2
    Ae 2
    Документ4 страницы
    Ae 2
    Sebri
    Оценок пока нет
  • SEII - ch1 - PROCESSUS
    SEII - ch1 - PROCESSUS
    Документ6 страниц
    SEII - ch1 - PROCESSUS
    Houssam Boukhari
    Оценок пока нет
  • TD 1 (2020)
    TD 1 (2020)
    Документ4 страницы
    TD 1 (2020)
    Abir Abdelmoumen
    Оценок пока нет
  • Processus in C
    Processus in C
    Документ18 страниц
    Processus in C
    Chaimae Salsabil00
    Оценок пока нет
  • C1 Processus Flat
    C1 Processus Flat
    Документ28 страниц
    C1 Processus Flat
    anas
    Оценок пока нет
  • DS SEPCcor 14 11 2017-1
    DS SEPCcor 14 11 2017-1
    Документ11 страниц
    DS SEPCcor 14 11 2017-1
    Dhia Benkhaled
    Оценок пока нет
  • Process Us
    Process Us
    Документ4 страницы
    Process Us
    Franc Zogning
    Оценок пока нет
  • Tdtme67 Cor
    Tdtme67 Cor
    Документ41 страница
    Tdtme67 Cor
    Edouagodi MbohB
    Оценок пока нет
  • Chap 1 Processus
    Chap 1 Processus
    Документ45 страниц
    Chap 1 Processus
    My Driss LAANAOUI
    Оценок пока нет