Implement fully the latest TD1's exercice
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 5 Jun 2017 19:49:58 +0000 (21:49 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 5 Jun 2017 19:49:58 +0000 (21:49 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
.gitignore
TD1/part_three/balle/balle.c
TD1/part_three/lanceur.c

index f7925e55d2f69cf464ca0e9ee60ebb895ee8218f..063ef1e8486158061f9b52065eae736b79b88ea1 100644 (file)
@@ -1,4 +1,6 @@
 exo*
 exo*
+lanceur
+balle
 *.static
 *.dynamic
 # for cygwin
 *.static
 *.dynamic
 # for cygwin
index 7881ec5a4b48b65f56d52031f5d7917a7c771c83..15b351b373a47e26202abb2a4d0b8eed3ce80941 100644 (file)
 int main() {
 
     srand(time(NULL));
 int main() {
 
     srand(time(NULL));
-    int randValue = rand() % 5 + 1;
+    int randvalue = rand() % 5 + 1;
 
     printf("[%d] Je suis la balle et je vole\n", getpid());
 
 
     printf("[%d] Je suis la balle et je vole\n", getpid());
 
-    sleep(randValue);
+    sleep(randvalue);
 
 
-    return EXIT_SUCCESS;
+    return randvalue;
 }
 }
index 40ee7dd50c77dc7060c421928d3919163b5bbdd5..df339c0be9467cb6061ac91daaa0fc8094cd880f 100644 (file)
@@ -7,11 +7,25 @@
 #include <unistd.h>
 
 int main() {
 #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());
 
 
     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;
 }
 
     return EXIT_SUCCESS;
 }