From 8b366a33f716bf48bc17381f996934233499124d Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Thu, 24 Sep 2020 11:44:54 +0200 Subject: [PATCH] p fork wait exit ok --- .../p_fork_wait_exit.c | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/2020-2021/S3T_TP_03_PROCESSUS-2-PROG/Demonstrations_a_etudier/p_fork_wait_exit.c b/2020-2021/S3T_TP_03_PROCESSUS-2-PROG/Demonstrations_a_etudier/p_fork_wait_exit.c index 92fc040..2765e52 100644 --- a/2020-2021/S3T_TP_03_PROCESSUS-2-PROG/Demonstrations_a_etudier/p_fork_wait_exit.c +++ b/2020-2021/S3T_TP_03_PROCESSUS-2-PROG/Demonstrations_a_etudier/p_fork_wait_exit.c @@ -29,10 +29,9 @@ int main(int argc, char *argv[]) /**********************/ /* PARTIE A COMPLETER */ /**********************/ - + int infosRetour; int res = fork(); - int max = atoi(argv[1]); - + int max=atoi(argv[1]); if (res < 0) { printf("ERREUR FORK\n"); @@ -44,23 +43,23 @@ int main(int argc, char *argv[]) printf("Je suis le fils :\n"); printf("pid : %d\n", getpid()); printf("ppid : %d\n", getppid()); - for (int i = 0; i < max; i++) - { - printf("/"); - } + + printf("Hush now quiet now It's time to go to bed for 3 seconds...\n"); + sleep(3); + printf("I know this one ! :D"); + printf("\n\n"); + exit(max); } else { /************************** PERE ***********************/ - wait(NULL); + wait(&infosRetour); printf("Je suis le père :\n"); printf("pid : %d\n", getpid()); printf("ppid : %d\n", getppid()); + printf("%d", WEXITSTATUS(infosRetour)); + - for (int i = 0; i < max; i++) - { - printf("*"); - } printf("\n\n"); } }