Add TD3 code.
[TD_SE.git] / TD3 / exo2 / exo2.c
diff --git a/TD3/exo2/exo2.c b/TD3/exo2/exo2.c
new file mode 100644 (file)
index 0000000..0e58bb8
--- /dev/null
@@ -0,0 +1,35 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <wait.h>
+
+int main()
+{
+       pid_t pid;
+
+       if ((pid = fork()) == -1) {
+               perror("erreur");
+               exit(EXIT_FAILURE);
+       } else if (pid == 0) {
+               for (int i = 1; i <= 50; i++) {
+                       printf("%d\n", i);
+               }
+               return 0;
+       }
+
+       // Assure la fin du premier fils avant l'execution du deuxième
+       wait(NULL);
+
+       if ((pid = fork()) == -1) {
+               perror("erreur");
+               exit(EXIT_FAILURE);
+       } else if (pid == 0) {
+               for (int i = 50; i <= 100; i++) {
+                       printf("%d\n", i);
+               }
+               return 0;
+       }
+
+       exit(EXIT_SUCCESS);
+}