Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<errno.h>
- #include<unistd.h>
- #include<sys/types.h>
- #include<sys/fcntl.h>
- #include<sys/stat.h>
- int main ()
- {
- int comp =0; // c'est un compteur
- pid_t pid_fils1 , pid_fils2;
- printf("1-compteur =%d \n",comp);
- pid_fils1 = fork( );
- if ( pid_fils1== -1 )
- {
- printf(" ERREUR !!");
- return (1);
- }
- if (pid_fils1 == 0)
- {
- comp++;
- printf("2-compteur %d \n",comp);
- pid_fils2 = fork ( );
- if (pid_fils2 == -1)
- {
- printf("ERREUR!!");
- return (1);
- }
- if (pid_fils2==0)
- {
- comp++;
- printf("3-compteur %d \n",comp);
- }
- }
- else
- {
- comp --;
- printf("4-compteur %d \n",comp);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement