From 720c45c786b902933b74162b1b05b04ab0be97a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 5 Jun 2017 21:49:58 +0200 Subject: [PATCH] Implement fully the latest TD1's exercice MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .gitignore | 2 ++ TD1/part_three/balle/balle.c | 6 +++--- TD1/part_three/lanceur.c | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f7925e5..063ef1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ exo* +lanceur +balle *.static *.dynamic # for cygwin diff --git a/TD1/part_three/balle/balle.c b/TD1/part_three/balle/balle.c index 7881ec5..15b351b 100644 --- a/TD1/part_three/balle/balle.c +++ b/TD1/part_three/balle/balle.c @@ -10,11 +10,11 @@ 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()); - sleep(randValue); + sleep(randvalue); - return EXIT_SUCCESS; + return randvalue; } diff --git a/TD1/part_three/lanceur.c b/TD1/part_three/lanceur.c index 40ee7dd..df339c0 100644 --- a/TD1/part_three/lanceur.c +++ b/TD1/part_three/lanceur.c @@ -7,11 +7,25 @@ #include 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; } -- 2.34.1