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>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #define ODCZYT 0
- #define ZAPIS 1
- #define SPIJ 3
- #define LEN 10
- #define nmbProcess 3
- using namespace std;
- int main()
- {
- mkfifo("pipeFile", 0666);
- while (true)
- {
- char* text = new char[LEN];
- cout<<"enter "<<endl;
- cin>>text;
- int process_1 = fork();
- int end1 = 1;
- int k = nmbProcess;
- if(process_1 == -1)
- return 1;
- else if (process_1 != 0)
- {
- cout<<"Process A"<<endl;
- int file = open("pipeFile", 0666);
- sleep(SPIJ);
- write(file, text, sizeof(text));
- sleep(SPIJ-2);
- close(file);
- delete []text;
- }
- else
- {
- cout<<"Process B"<<endl;
- int file = open("pipeFile", O_RDONLY);
- read(file, text, sizeof(text));
- close(file);
- char *change = new char [LEN];
- int end2 = 1;
- 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);
- file = open("pipeFile", O_WRONLY);
- write(file, change, sizeof(change));
- close(file);
- sleep(SPIJ-2);
- delete []change;
- }
- else
- {
- cout<<"Process C"<<endl;
- char* text2 = new char[LEN];
- sleep(SPIJ);
- int file = open("pipeFile", O_RDONLY);
- read(file, text2, sizeof(text));
- close(file);
- sleep(SPIJ-2);
- cout<<"ODP: "<<text2<<endl;
- sleep(SPIJ-2);
- delete []text2;
- }
- }
- while(k-->0)
- int d = waitpid(-1,NULL,0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement