Implement fully the latest TD1's exercice
[TD_IML.git] / TD1 / part_three / lanceur.c
index 40ee7dd50c77dc7060c421928d3919163b5bbdd5..df339c0be9467cb6061ac91daaa0fc8094cd880f 100644 (file)
@@ -7,11 +7,25 @@
 #include <unistd.h>
 
 int main() {
+    int child_rt_status = 0;
 
     printf("[%d] Je suis le lanceur\n", getpid());
     printf("[%d] Je lance la balle\n", getpid());
 
-    execl("/Users/fraggle/src/TD_IML-git/TD1/part_three/balle/balle", "balle");
+    pid_t cpid = fork();
+    if (cpid < 0) {
+        perror("fork failure\n");
+        exit(EXIT_FAILURE);
+    }
+
+    if (cpid == 0) {
+        execl("/home/fraggle/src/TD_IML-git/TD1/part_three/balle/balle", "balle", (char*)NULL);
+        perror("execl failure\n");
+        exit(EXIT_FAILURE);
+    } else {
+        wait(&child_rt_status);
+        printf("[%d] La balle est arrivee apres %d secondes\n", getpid(), WEXITSTATUS(child_rt_status));
+    }
 
     return EXIT_SUCCESS;
 }