ASR3.1/TD2/Exemple1.c
2021-09-22 15:20:07 +02:00

26 lines
534 B
C
Raw Permalink 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()); 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);
}