Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define SIZE_BUFFOR 100
- int main() {
- pid_t proces1, proces2;
- char buffor[SIZE_BUFFOR];
- int pipe1[2];
- int pipe2[2];
- int pipe3[2];
- int pipe4[2];
- if(pipe(pipe1) < 0){
- exit(10);
- }
- if(pipe(pipe2) < 0){
- exit(10);
- }
- if(pipe(pipe3) < 0){
- exit(10);
- }
- if(pipe(pipe4) < 0){
- exit(10);
- }
- proces1 = fork();
- switch(proces1){
- case 0:
- {
- printf("PP1:%d\n", getpid());
- char tekst[SIZE_BUFFOR];
- printf("Podaj tekst: ");
- scanf("%s", tekst);
- close(pipe1[0]);
- write(pipe1[1], tekst, SIZE_BUFFOR);
- char odczyt_konwersji[SIZE_BUFFOR];
- close(pipe4[1]);
- read(pipe4[0], odczyt_konwersji, SIZE_BUFFOR);
- printf("WYNIK: %s\n", odczyt_konwersji);
- exit(0);
- }
- case -1:
- printf("Blad funkcji fork\n");
- exit(1);
- default:
- close(pipe1[1]);
- read(pipe1[0], buffor, SIZE_BUFFOR);
- write(pipe2[1], buffor, SIZE_BUFFOR);
- }
- proces2 = fork();
- switch(proces2){
- case 0:
- {
- char tekst_do_konwersji[50];
- close(pipe2[1]);
- read(pipe2[0], tekst_do_konwersji, SIZE_BUFFOR);
- for(int i = 0; i < sizeof(tekst_do_konwersji); i++){
- tekst_do_konwersji[i] = toupper(tekst_do_konwersji[i]);
- }
- close(pipe3[0]);
- write(pipe3[1], tekst_do_konwersji, SIZE_BUFFOR);
- exit(0);
- }
- case -1:
- printf("Blad funkcji fork\n");
- exit(1);
- default:
- wait(NULL);
- close(pipe3[1]);
- read(pipe3[0], buffor, SIZE_BUFFOR);
- close(pipe4[0]);
- write(pipe4[1], buffor, SIZE_BUFFOR);
- }
- wait(NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment