Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string>
- #include <sys/wait.h>
- #define ODCZYT 0
- #define ZAPIS 1
- #define SPIJ 3
- #define LEN 10
- #define nmbProcess 3
- using namespace std;
- int main()
- {
- int pipe_arr[2];
- while (true)
- {
- char* text = new char[LEN];
- cout<<"enter "<<endl;
- cin>>text;
- pipe(pipe_arr);
- int process_1 = fork();
- int k = nmbProcess;
- if(process_1 == -1)
- return 1;
- else if (process_1 != 0)
- {
- cout<<"Process A"<<endl;
- sleep(SPIJ);
- write(pipe_arr[ZAPIS], text, sizeof(text));
- sleep(SPIJ-2);
- close(pipe_arr[ZAPIS]);
- delete []text;
- }
- else
- {
- cout<<"Process B"<<endl;
- read(pipe_arr[ODCZYT], text, sizeof(text));
- close(pipe_arr[ODCZYT]);
- char *change = new char [LEN];
- int pipe_arr2[2];
- pipe(pipe_arr2);
- int process_2 = fork();
- if (process_2 == -1)
- return 1;
- else if (process_2 != 0)
- {
- for (int i=0; text[i]!= 0; i++)
- {
- change[i] = text[i];
- if(text[i]<= 'z' && text[i]>='a')
- {
- change[i]= text[i] - 32;
- }
- }
- sleep(SPIJ);
- write(pipe_arr2[ZAPIS], change, sizeof(change));
- sleep(SPIJ-2);
- close(pipe_arr2[ZAPIS]);
- delete []change;
- }
- else
- {
- cout<<"Process C"<<endl;
- char* text2 = new char[LEN];
- sleep(SPIJ);
- read(pipe_arr2[ODCZYT], text2, sizeof(text));
- sleep(SPIJ-2);
- close(pipe_arr2[ODCZYT]);
- cout<<"ODP: "<<text2<<endl;
- delete []text2;
- }
- }
- while(k-->0)
- int d = waitpid(-1,NULL,0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement