orzechtbg

Współbieżne.LAB4. ZAD23.czytajacy

Oct 28th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <wait.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10.  
  11. extern int errno; //numer ostatniego błędu
  12. #define FIFO1 "/tmp/fifo.1"
  13. int main()
  14. {
  15. char buff[1024];
  16.  
  17. int fifo;
  18. int flagi=O_RDONLY /*| O_NDELAY*/ ;
  19. if ((fifo = open(FIFO1, flagi)) < 0)
  20.     perror("nie moze otworzyc fifo1 do pisania");
  21. int n=read(fifo,buff,sizeof(buff)); //fd jest deskryptorem czytanego pliku ,buf jest adresem struktory danych uzytkownika do ktorego wczytujemy dane ,count jest to liczba bajtow, ktore chce wczytac uzytkownik
  22. if (n<=0)
  23.     perror("blad zapisu do fifo");
  24. else{
  25. buff[n]='\0';
  26.                 write(1,buff,n);
  27.          printf("\n");
  28.         }
  29.    
  30. unlink(FIFO1); //usuniecie kolejki
  31. return 0;    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment