1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int fils1, fils2;
int A, B, C, D, E, result;
int main(void)
{
fils1 = fork();
// fils2 = fork();
if (fils1 == 0){
int re;
re = 5+1;
printf("re dans 1er fistion %d\n", re);
exit(re);}
// else{
fils2 = fork();
if (fils2 == 0){
int re;
re = 5-1;
printf("re dans 2eme fistion %d\n", re);
exit(re);}
else
{
printf("que dans le papa\n%d\n%d\n",fils1,fils2);
A=wait(&C);
B=wait(&D);
printf("A:%d\tB%d\n",A,B);
C=WEXITSTATUS(C);
D=WEXITSTATUS(D);
printf("Res1:%d\tRes2:%d\n",C,D);
A = 1+1;
result = ( C + D ) / A;
printf( "Resultat du père %d\n", result);
}
return 0;
} |
Partager