Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <limits.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- void producent(char const* FILERS ,int pipefd)
- {
- char bufor[100];
- FILE *file;
- file=fopen(FILERS, "r");
- int in= fopen("potok", "r"); //// dodane
- if(file==NULL){
- perror("Error");
- exit(1);
- }
- while(fgets(bufor, 100, file) != NULL)
- {
- printf("Przesyłam dane : %s", bufor);
- write(pipefd, bufor, 100);
- }
- /////
- if( write( in , bufor , 100 ) == -1)
- {
- perror("Funckja write zwrocila blad ");
- exit(2);
- }
- //////
- printf("Send..\n");
- }
- void konsument(char const* FILERS, int pipefd)
- {
- char bufor[100];
- FILE * file;
- file= fopen(FILERS, "w");
- int out= fopen("potok", "w");
- if(file==NULL){
- perror("Error");
- exit(1);
- }
- read(out, bufor,100);
- int x;
- do{
- x=read(pipefd,bufor,100);
- if(x!=0)
- {
- fputs(bufor,file);
- printf("Odbieram dane : %s", bufor);
- }
- }while(x>0);
- sleep(1);
- printf("Accepted\n");
- }
- ////////main/////////////////////////////
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <limits.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- void producent( int );
- void konsument( int );
- char const* in="input.txt";
- char const* out="output.txt";
- int main()
- {
- mkfifo("potok", 0644);
- int pipefd[2];
- if (pipe(pipefd) == -1){
- perror("Pipe error");
- exit(EXIT_FAILURE);
- }
- switch(fork()) {
- case -1:
- perror("ErroR");
- exit(EXIT_FAILURE);
- break;
- case 0:
- close(pipefd[0]);
- producent(in,pipefd[1]);
- close(pipefd[1]);
- break;
- default:
- close(pipefd[1]);
- konsument(out,pipefd[0]);
- close(pipefd[0]);
- wait(NULL);
- break;
- }
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement