Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<errno.h>
  4. #include<unistd.h>
  5. #include<sys/types.h>
  6. #include<sys/fcntl.h>
  7. #include<sys/stat.h>
  8.  
  9. int main ()
  10. {
  11. int comp =0; // c'est un compteur
  12. pid_t pid_fils1 , pid_fils2;
  13.  
  14. printf("1-compteur =%d \n",comp);
  15.  
  16. pid_fils1 = fork( );
  17. if ( pid_fils1== -1 )
  18. {
  19. printf(" ERREUR !!");
  20. return (1);
  21. }
  22.  
  23. if (pid_fils1 == 0)
  24. {
  25. comp++;
  26. printf("2-compteur %d \n",comp);
  27. pid_fils2 = fork ( );
  28. if (pid_fils2 == -1)
  29. {
  30. printf("ERREUR!!");
  31. return (1);
  32. }
  33. if (pid_fils2==0)
  34. {
  35. comp++;
  36. printf("3-compteur %d \n",comp);
  37. }
  38. }
  39. else
  40. {
  41. comp --;
  42. printf("4-compteur %d \n",comp);
  43. }
  44.  
  45. return 1;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement