From: Jérôme Benoit Date: Mon, 5 Jun 2017 19:49:58 +0000 (+0200) Subject: Implement fully the latest TD1's exercice X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=720c45c786b902933b74162b1b05b04ab0be97a2;p=TD_IML.git Implement fully the latest TD1's exercice Signed-off-by: Jérôme Benoit --- 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; }