Implement fully the latest TD1's exercice
[TD_IML.git] / TD1 / part_three / lanceur.c
1 #include <sys/types.h>
2 #include <sys/wait.h>
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8
9 int main() {
10 int child_rt_status = 0;
11
12 printf("[%d] Je suis le lanceur\n", getpid());
13 printf("[%d] Je lance la balle\n", getpid());
14
15 pid_t cpid = fork();
16 if (cpid < 0) {
17 perror("fork failure\n");
18 exit(EXIT_FAILURE);
19 }
20
21 if (cpid == 0) {
22 execl("/home/fraggle/src/TD_IML-git/TD1/part_three/balle/balle", "balle", (char*)NULL);
23 perror("execl failure\n");
24 exit(EXIT_FAILURE);
25 } else {
26 wait(&child_rt_status);
27 printf("[%d] La balle est arrivee apres %d secondes\n", getpid(), WEXITSTATUS(child_rt_status));
28 }
29
30 return EXIT_SUCCESS;
31 }