Add shared mem course example code.
[TD_SE.git] / TD3 / exo2 / exo2.c
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <wait.h>
6
7 int main()
8 {
9 pid_t pid;
10
11 if ((pid = fork()) == -1) {
12 perror("erreur");
13 exit(EXIT_FAILURE);
14 } else if (pid == 0) {
15 for (int i = 1; i <= 50; i++) {
16 printf("%d\n", i);
17 }
18 return 0;
19 }
20
21 // Assure la fin du premier fils avant l'execution du deuxième
22 wait(NULL);
23
24 if ((pid = fork()) == -1) {
25 perror("erreur");
26 exit(EXIT_FAILURE);
27 } else if (pid == 0) {
28 for (int i = 50; i <= 100; i++) {
29 printf("%d\n", i);
30 }
31 return 0;
32 }
33
34 exit(EXIT_SUCCESS);
35 }