Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- int pfd1[2], pfd2[2], pfd3[2];
- int fiu1, fiu2, fd;
- int bits_cititi, bits = 100, cifre = 0, cifre_dist = 0;
- //buffers
- char *bufer = (char *) malloc (sizeof(char)*bits);
- char bufer_numere[100];
- int stats[10];
- if(pipe(pfd1) < 0)
- {
- printf("Eroare la crearea pipe-ului 1!\n");
- exit(-4);
- }
- if(pipe(pfd2) < 0)
- {
- printf("Eroare la crearea pipe-ului 2!\n");
- exit(-7);
- }
- if(pipe(pfd3) < 0)
- {
- printf("Eroare la crearea pipe-ului 3!\n");
- exit(-8);
- }
- if((fiu1=fork()) < 0)
- {
- printf("Eroare la crearea fiului 1...\n");
- exit(-1);
- }
- else if (fiu1 == 0)
- {
- close(pfd1[1]);
- while(bits_cititi = read(pfd1[0], bufer, bits))
- {
- for(int i=0; i<strlen(bufer); i++)
- {
- if(bufer[i] > '0' && bufer[i] < '9')
- {
- bufer_numere[cifre] = bufer[i];
- cifre++;
- }
- }
- }
- close(pfd1[0]);
- write(pfd1[1], bufer_numere, strlen(bufer_numere));
- close(pfd1[0]);
- }
- if((fiu2=fork()) < 0)
- {
- printf("Eroare la crearea fiului 2...\n");
- exit(-2);
- }
- else if (fiu2 == 0)
- {
- close(pfd1[1]);
- while(bits_cititi = read(pfd1[0], bufer, bits))
- {
- for(int j=0; j<bits_cititi; j++)
- {
- stats
- }
- }
- }
- if(fiu1 != 0 && fiu2 != 0)
- {
- if((fd = open(argv[1], O_RDONLY)) < 0)
- {
- printf("Eroare la deschiderea fisierului !\n");
- exit(-3);
- }
- close(pfd1[0]);
- while(bits_cititi = read(fd, bufer, bits))
- {
- write(pfd1[1], bufer, bits_cititi);
- }
- close(pfd1[1]);
- exit(-5);
- }
- if(fiu1 < 0 || fiu2 < 0 )
- {
- printf("Eroare la Fork !\n");
- exit(-6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement