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
 
#include <sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdio.h>
int main()
{
	int pid;
	int vals;
	int pidf;
	int i;
	for(i=0;i<50;i++)printf("c'est moi le pere\n");
	pid=fork();
	switch(pid)
	{
	case -1: 
		printf("Echec de fork");
		exit(EXIT_FAILURE);
	case 0: 
 
 
	for(i=0;i<200;i++)printf("c'est le fils");
		exit(EXIT_SUCESS);
	break;
	default: 
 
	pidf=wait(&vals);
 
	break;
	}
 
 
 
 
	printf("%d    %d\n",pidf,pid);
return 0;
 
}
pidf=wait(&vals); pidf va récupérer le numéro du processus fils ou père ?