Advertisement
Guest User

Untitled

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