From 2fff4e7471783628d335e69a6560dc02f978a177 Mon Sep 17 00:00:00 2001 From: Tom Moguljak Date: Tue, 26 Sep 2023 15:09:30 +0200 Subject: [PATCH] Ajout de l'exo 4 --- TP3/Exo4/exo4.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 TP3/Exo4/exo4.c diff --git a/TP3/Exo4/exo4.c b/TP3/Exo4/exo4.c new file mode 100644 index 0000000..1bd2bce --- /dev/null +++ b/TP3/Exo4/exo4.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc,char * argv[]) +{ + int status; + pid_t p, n; + + + p = fork(); + assert(p != -1); + + if (p==0) { + printf("Le retour du fork est %d\n", p); + printf("Mon PID est %d\n", getpid()); + printf("Le PID de mon pere est %d\n", getppid()); + sleep(4); + exit(2); + } + + if (p>0) { + sleep(1); + printf("\nLe retour du fork est %d\n", p); + printf("Mon PID est %d\n", getpid()); + printf("Le PID de mon pere est %d\n", getppid()); + n = wait(&status); + printf("Le fils %d a termine avec le code %d\n", n, WEXITSTATUS(status)); + execl("/usr/bin/ps", "ps", "-ef", NULL); + exit(0); + } +} \ No newline at end of file