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