G. FIFO Client/Server Program in Unix Using C Programming

FIFO Server Program

/* FIFO Server Program In C*/

#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
int main() {
   char fname[25] = "";
   char fcontent[100] = "";
   int fd, fd1, fd2;
   mkfifo("fifo1", 0600);
   mkfifo("fifo2", 0600);
   fd = open("fifo1", O_RDONLY);
   fd1 = open("fifo2", O_WRONLY);
   read(fd, fname, 25);
   fd2 = open(fname, O_RDONLY);
   while (read(fd2, fcontent, 100) != 0) {
      printf("%s\n", fcontent);
      if (fd < 0)
         write(fd1, "file not exit", 14);
      else
         write(fd1, fcontent, strlen(fcontent));
   }
   close(fd);
   close(fd1);
   close(fd2);
}

FIFO Client Program

/* FIFO Client Program In C*/

#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
int main() {
   char s[100] = "";
   char s1[1000] = "";
   int fd, fd1;
   fd = open("fifo1", O_WRONLY);
   fd1 = open("fifo2", O_RDONLY);
   printf("\nEnter the file name:");
   scanf("%s", s);
   write(fd, s, strlen(s));
   while (read(fd1, s1, 1000) != 0) {
      printf("File Content :%s", s1);
   }
}

Sample Output

Enter the file name:strcmp.c

File Content :#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdlib.h>
include<string.h>
int main(int argc,char *argv[])
{
        if(strcmp(argv[1],argv[2])==0)
                printf("The gistrcmp.c
#strcmp.cFile Content :include<string.h>
int main(int argc,char *argv[])
{
       if(strcmp(argv[1],argv[2])==0)
ven strings are equal");
        else
                printf("The strings are not equal");
}
rgv[2])==0)
                printf("The gistrcmp.c
                printf("The gistrcmp.cFile Content :ven strings are equal");
        else
                printf("The strings are not equal");
}
                printf("The gistrcmp.c[1]+  Done                    ./server