Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9.  
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13. int pfd1[2], pfd2[2], pfd3[2];
  14. int fiu1, fiu2, fd;
  15. int bits_cititi, bits = 100, cifre = 0, cifre_dist = 0;
  16.  
  17. //buffers
  18. char *bufer = (char *) malloc (sizeof(char)*bits);
  19. char bufer_numere[100];
  20. int stats[10];
  21.  
  22.  
  23.  
  24. if(pipe(pfd1) < 0)
  25. {
  26. printf("Eroare la crearea pipe-ului 1!\n");
  27. exit(-4);
  28. }
  29. if(pipe(pfd2) < 0)
  30. {
  31. printf("Eroare la crearea pipe-ului 2!\n");
  32. exit(-7);
  33. }
  34. if(pipe(pfd3) < 0)
  35. {
  36. printf("Eroare la crearea pipe-ului 3!\n");
  37. exit(-8);
  38. }
  39.  
  40. if((fiu1=fork()) < 0)
  41. {
  42. printf("Eroare la crearea fiului 1...\n");
  43. exit(-1);
  44. }
  45. else if (fiu1 == 0)
  46. {
  47. close(pfd1[1]);
  48. while(bits_cititi = read(pfd1[0], bufer, bits))
  49. {
  50. for(int i=0; i<strlen(bufer); i++)
  51. {
  52. if(bufer[i] > '0' && bufer[i] < '9')
  53. {
  54. bufer_numere[cifre] = bufer[i];
  55. cifre++;
  56. }
  57. }
  58. }
  59. close(pfd1[0]);
  60. write(pfd1[1], bufer_numere, strlen(bufer_numere));
  61. close(pfd1[0]);
  62. }
  63.  
  64. if((fiu2=fork()) < 0)
  65. {
  66. printf("Eroare la crearea fiului 2...\n");
  67. exit(-2);
  68. }
  69. else if (fiu2 == 0)
  70. {
  71. close(pfd1[1]);
  72. while(bits_cititi = read(pfd1[0], bufer, bits))
  73. {
  74. for(int j=0; j<bits_cititi; j++)
  75. {
  76. stats
  77. }
  78. }
  79. }
  80.  
  81. if(fiu1 != 0 && fiu2 != 0)
  82. {
  83. if((fd = open(argv[1], O_RDONLY)) < 0)
  84. {
  85. printf("Eroare la deschiderea fisierului !\n");
  86. exit(-3);
  87. }
  88.  
  89. close(pfd1[0]);
  90.  
  91. while(bits_cititi = read(fd, bufer, bits))
  92. {
  93. write(pfd1[1], bufer, bits_cititi);
  94. }
  95.  
  96. close(pfd1[1]);
  97. exit(-5);
  98. }
  99.  
  100. if(fiu1 < 0 || fiu2 < 0 )
  101. {
  102. printf("Eroare la Fork !\n");
  103. exit(-6);
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement