ASR31-valarche-2021/Exemples/03-Fork/wait.c
2021-09-22 13:36:31 +02:00

27 lines
545 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
int main() {
pid_t fils_pid ;
fils_pid = fork ();
if ( fils_pid == 0) {
printf("Je suis le fils avec pid %d\n",getpid()); sleep(1); exit(3);
} else {
if (fils_pid > 0) {
printf ("Je suis le pere avec pid %d.\n" , getpid ());
printf("Jattends que mon fils se termine\n");
wait (NULL) ;
printf("Normalement mon fils en a fini!\n");
} else {
printf("Erreur dans la creation du fils\n");
}
}
exit (0);
}