Wednesday, 20 February 2013

Program:To write a C program that illustrates communication between unrelated processes using named pipe.

/*
 Program:To write a C program that illustrates communication between unrelated
        processes using named pipe.

*/

   //sender.c
  #include
   #include
   #include
   #include
   #include
   #include
   main()
   {
           int fd,p;
          char *msg="Hello Named Pipe";
          p=mknod("/tmp/mansoorpipe",S_IFIFO | 0666,0);
          if(p==-1)
          {
                  printf("\n Names Pipe failure\n ");
                  return;
          }
          fd=open("/tmp/mansoorpipe",O_WRONLY);
          if(fd<0 br="">          {
                  printf("\n File Opening Problem\n ");
                  _exit(0);
          }
          write(fd,msg,strlen(msg)+1);


//reciever.c



 1 #include
  2 #include
  3 #include
  4 #include
  5 #include
  6 main()
  7 {
  8         char buf[100];
  9         int fd,i;
 10         fd=open("/tmp/mansoorpipe",O_RDONLY);
 11         if(fd<0 br=""> 12         {
 13                 printf("File Opening Problem");
 14                 return;
 15         }
 16         i=read(fd,buf,100);
 17         buf[i]='\0';
 18         printf("%s",buf);
 19         close(fd);
 20 }




/*--------------------INPUT/OUTPUT--------------------

-bash-3.2$ cc sender.c -o sender
-bash-3.2$ cc reciever.c -o reciever
hello named pipe
-bash-3.2$ cat fact.c > /tmp/mansoorpipe
 cat < /tmp/mansoorpipe facts


--------------------------------------------------------*/                                  

No comments:

Post a Comment