Tobiahao

S01_LAB02_06b

Nov 13th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. /*
  2. Napisz dwa niezale ż ne programy, które b ę d ą się komunikowa ł y przy pomocy
  3. kolejki FIFO. Zadanie wykonaj w dwóch wariantach, tak jak zadanie 4. Po
  4. zako ń czeniu komunikacji kolejk ę nale ż y usun ąć .
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <fcntl.h>
  12. #include <unistd.h>
  13. #include <string.h>
  14.  
  15. #define BUFFER_SIZE 256
  16. #define FIFO_DIR "./fifo"
  17.  
  18. int main(void)
  19. {
  20.     int fd;
  21.     char buffer[BUFFER_SIZE];
  22.     memset(buffer, '\0', BUFFER_SIZE);
  23.  
  24.     if((fd = open(FIFO_DIR, O_RDONLY)) == -1){
  25.         perror("open");
  26.         return EXIT_FAILURE;
  27.     }
  28.  
  29.     if(read(fd, buffer, BUFFER_SIZE) == -1){
  30.         perror("read");
  31.         return EXIT_FAILURE;
  32.     }
  33.  
  34.     printf("Przeslana wiadomosc: %s\n", buffer);
  35.  
  36.     if(close(fd) == -1){
  37.         perror("close");
  38.         return EXIT_FAILURE;
  39.     }
  40.  
  41.     return EXIT_SUCCESS;
  42. }
Add Comment
Please, Sign In to add comment