Advertisement
Guest User

writer

a guest
May 25th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1.  
  2.     #include <stdio.h>
  3.     #include <fcntl.h>
  4.     #include <sys/stat.h>
  5.     #include <sys/types.h>
  6.     #include <unistd.h>
  7.     #define MAX_BUF 1024
  8.     int main()
  9.     {
  10.      int fd;
  11.      char buf[MAX_BUF];
  12.  
  13.      char * myfifo = "/tmp/myfifo";
  14.  
  15.      /* create the FIFO (named pipe) */
  16.      mkfifo(myfifo, 0666);
  17.  
  18.      /* write message to the FIFO */
  19.      fd = open(myfifo, O_WRONLY);
  20.      write(fd, "Luke, to ja jestem twoim ojcem!", sizeof("Luke, to ja jestem twoim ojcem!"));
  21.      close(fd);
  22.  
  23.      wait(NULL);
  24.      fd = open(myfifo, O_RDONLY);
  25.      read(fd, buf, MAX_BUF);
  26.      printf("Odebrano: %s\n", buf);
  27.      close(fd);
  28.  
  29.      /* remove the FIFO */
  30.      unlink(myfifo);
  31.      return 0;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement