/* The server's program */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>      // exit
#include <unistd.h>
#include <fcntl.h>       // open, mknod

int main() 
{
  char buf[BUFSIZ];
  int fd,n;

  /* create a special file - the FIFO pipe , set RWX access rights */
 
  mknod("/tmp/pipe", S_IFIFO | S_IRWXU,0);

  printf("FIFO created\n");

  /* open FIFO for reading */
 
  fd = open("/tmp/pipe", O_RDONLY);

  printf("FIFO opened\n");
  
  if (fd < 0 ) 
    {
      perror("Open");
      exit(1);
    }
  
  /* read data from FIFO */

  while ((n=read(fd,buf,BUFSIZ-1)) > 0) 
    {
      buf[n]=0;
      printf("Data read: %s\n",buf);
    }
  
  close (fd);

  exit(0);
}
