Advertisement
Guest User

Untitled

a guest
May 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <string>
  6. #include <sys/wait.h>
  7. #include <fcntl.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10.  
  11. #define ODCZYT 0
  12. #define ZAPIS 1
  13. #define SPIJ 3
  14. #define LEN 10
  15. #define nmbProcess 3
  16.  
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. mkfifo("pipeFile", 0666);
  22.  
  23. while (true)
  24. {
  25. char* text = new char[LEN];
  26. cout<<"enter "<<endl;
  27. cin>>text;
  28.  
  29. int process_1 = fork();
  30. int end1 = 1;
  31. int k = nmbProcess;
  32.  
  33. if(process_1 == -1)
  34. return 1;
  35. else if (process_1 != 0)
  36. {
  37. cout<<"Process A"<<endl;
  38. int file = open("pipeFile", 0666);
  39. sleep(SPIJ);
  40. write(file, text, sizeof(text));
  41. sleep(SPIJ-2);
  42. close(file);
  43.  
  44.  
  45. delete []text;
  46. }
  47. else
  48. {
  49. cout<<"Process B"<<endl;
  50. int file = open("pipeFile", O_RDONLY);
  51. read(file, text, sizeof(text));
  52. close(file);
  53. char *change = new char [LEN];
  54. int end2 = 1;
  55.  
  56. int process_2 = fork();
  57.  
  58. if (process_2 == -1)
  59. return 1;
  60. else if (process_2 != 0)
  61. {
  62. for (int i=0; text[i]!= 0; i++)
  63. {
  64. change[i] = text[i];
  65. if(text[i]<= 'z' && text[i]>='a')
  66. {
  67. change[i]= text[i] - 32;
  68. }
  69. }
  70. sleep(SPIJ);
  71. file = open("pipeFile", O_WRONLY);
  72. write(file, change, sizeof(change));
  73. close(file);
  74. sleep(SPIJ-2);
  75. delete []change;
  76.  
  77. }
  78. else
  79. {
  80. cout<<"Process C"<<endl;
  81. char* text2 = new char[LEN];
  82. sleep(SPIJ);
  83. int file = open("pipeFile", O_RDONLY);
  84. read(file, text2, sizeof(text));
  85. close(file);
  86. sleep(SPIJ-2);
  87. cout<<"ODP: "<<text2<<endl;
  88. sleep(SPIJ-2);
  89.  
  90. delete []text2;
  91. }
  92.  
  93. }
  94. while(k-->0)
  95. int d = waitpid(-1,NULL,0);
  96. }
  97.  
  98.  
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement