Tobiahao

S01_LAB02_06a

Nov 13th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 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 SOME_MESSAGE "Wiadomosc..."
  16. #define FIFO_DIR "./fifo"
  17.  
  18. int main(void)
  19. {
  20.     int fd;
  21.  
  22.     if(mkfifo(FIFO_DIR, 0600) == -1){
  23.         perror("mkfifo");
  24.         return EXIT_FAILURE;
  25.     }
  26.  
  27.     if((fd = open(FIFO_DIR, O_WRONLY)) == -1){
  28.         perror("open");
  29.         return EXIT_FAILURE;
  30.     }
  31.  
  32.     if(write(fd, SOME_MESSAGE, strlen(SOME_MESSAGE)) == -1){
  33.         perror("write");
  34.         return EXIT_FAILURE;
  35.     }
  36.  
  37.     if(close(fd) == -1){
  38.         perror("close");
  39.         return EXIT_FAILURE;
  40.     }
  41.  
  42.     if(unlink(FIFO_DIR) == -1){
  43.         perror("unlink");
  44.         return EXIT_FAILURE;
  45.     }
  46.  
  47.     return EXIT_SUCCESS;
  48. }
Add Comment
Please, Sign In to add comment