Bonjour,

Pourriez-vous me dire dans quel(s) ordre(s) les instructions suivantes peuvent-elles être exécutées ? Car, d'après ce que j'ai compris, on ne sait pas trop comment l'ordonnanceur linux va réagir, et il peut y avoir plusieurs comportements, y compris certains qui font que notre programme ne fonctionne pas comme il devrait.

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
32
33
34
35
36
37
38
39
40
41
42
43
44
 
 
int pfd01[2], pfd10[2], pid;
 
void deroute(int signal)
{
    printf("Père %d : signal : %d recu \n", getpid(), sig);
}
 
void Pere()
{
    char message[BUFSIZ] = "hello";
    int pidP=getpid();
 
    if(signal(SIGUSR1,deroute)==SIGERR) erreur("signal"); // P1
    if(write(pfd01[1],&pidP,sizeof(int))==1) erreur("write"); //P2
    pause();//P3
    if(write(pfd01[1], message, 5)==-1) erreur("write");//P4
 
    exit(0);
}
 
void Fils()
{
    char message[BUFSIZ] ; int pidP;
 
    if(read(pfd01[0],&pidP,sizeof(int))==-1) erreur("read"); //F1
    if(kill(pidP,SIGUSR1)==-1) erreur("kill"); //F2
    if(read(pfd01[0], message) == -1 ) erreur("read"); //F3
 
    exit(0);
}
 
int main()
{
    if(pipe(pfd01)==-1) erreur("pipe");
    if(pipe(pfd10)==-1) erreur("pipe");
    switch(pid=fork())
    {
        case -1 : erreur("fork");
        case 0 : Fils();
    }
    Pere();
}
Par exemple, j'ai pensé à ceux-ci, est-ce qu'ils peuvent se produire ? :
F1 - P1 - P2 - P3 - F2 - F3 - P4

P1 - F1 - P2 - P3 - F3 - P4


Merci d'avance pour votre réponse.
Bonne soirée.