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;
}
#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;
}