ASR31-valarche-2021/Exemples/03-Fork/fork2b.c

24 lines
399 B
C
Raw Normal View History

2021-09-22 13:36:31 +02:00
/* Auteur : */
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int i, n = 3;
pid_t childpid;
for (i=0; i<n; i++) {
if ((childpid = fork()) == -1) break;
if (childpid == 0)
printf("Processus %d avec pere %d, i = %d\n", getpid(), getppid(), i);
}
while (wait(NULL) >= 0)
;
return EXIT_SUCCESS;
}