Pipeline with process named pipe is a device file that is present on the hard disk file with Mkfifo () to create a named pipe that can be used for communication between any two processes client.c (write end) #include <stdio.h> #include < stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <string.h > #include <fcntl.h> #define _PATH_ "/tmp/file.tmp" #define _size_ 100int main () { int ret=mkfifo (_path_,0666| S_IFIFO); //create fifo if (ret==-1) { perror ("Mkfifo"); return 1; } int fd=open (_PATH_,O_WRONLY); //open by the way of write if (fd<0) { printf ("open error\n"); } char buf[_size_]; memset (buf, ' while ', strlen (BUF) +1); {(1) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%s", buf); int ret=write (Fd,buf,strlen (BUF) +1); if (ret<0) { printf ("write error!\n"); break; } if (strncmp (buf, "Quit", 4) ==0) { break; } } close (FD); return 0;} SERVER.C (read end) #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <string.h># define _path_ "/tmp/file.tmp" #define _size_ 100int main () { int fd=open (_path_,o_rdonly); if (fd<0) { printf ("open file error\n"); return 1; } char buf[_SIZE_]; memset (buf, ' n ', sizeof (BUF)); while (1) { int ret=read (fd,buf,sizeof (BUF)); if (ret<=0) //error or read the end of file { printf ( "Error or read the end of file\n "); break; } printf ("%s\n", buf); if (strncmp (buf, "Quit", 4) ==0) { break; } } close (FD); return 0;} Results:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/16/wKioL1cTSGeQ2-o7AAAiihA6GWo898.png "title=" Image.png "alt=" Wkiol1ctsgeq2-o7aaaiiha6gwo898.png "/>
This article is from the "Voice of the Heart" blog, be sure to keep this source http://ljy789.blog.51cto.com/10697684/1764766
Implementation of Named Pipes (FIFO)