client.c: 1 #include <stdio.h> 2#include<stdlib.h> 3#include <string.h> 4#include<sys/stat.h> 5#include<sys/types.h> 6# include<unistd.h> 7#include<fcntl.h> 8#define _path_ "./tmp" 9#define size 100 10int main () 11 { 12 if (Mkfifo (_PATH_,0666| S_IFIFO) <0) 13 { 14 perror ("Mkfifo"); 15 return -1; 16 } 17 intfd=open (_PATH_,O_WRONLY); 18 if (fd<0) 19 { 20 perror ("open"); 21 return -1; 22 } 23 char buf[size]; 24 memset (buf, ' n ', SIZE); 25 while (1) 26 { 27 scanf ("%s", buf); 28 write (Fd,buf,strlen (BUF)); 29 } 30 close (FD); 31 return 0; 32 } server.c: 1 #include <stdio.h>2 #include <stdlib.h>3 #include <string.h>4 #include <sys/stat.h>5 #include <sys/types.h >6 #include <unistd.h> 7#include<fcntl.h> 8#define _PATH_ " ./tmp " 9#define size 100 10int main () 11 { 12 Intfd=open (_path_,o_rdonly); 13 if (fd<0) 14 { 15 perror ("open"); 16 return -1; 17 } 18 Char buf[size]; 19 while (1) 20 { 21 22 memset (buf, ' \ 0 ', SIZE); 23 read (Fd,buf,sizeof (BUF)); 24 printf ("%s\n", buf); 25 }&nbSp;26 close (FD); 27 return 0; 28 } makefile: 1.phony:all 2 all:client server 3 server:server.c 4 gcc -o [email protected] $^ 5client:client.c 6 gcc -o [ email protected] $^ 7.phony:clean 8clean: 9 rm -f client server tmp
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7F/04/wKiom1cPr4WTswenAAHyXUYjMeQ172.png "title=" Screenshot.png "alt=" Wkiom1cpr4wtswenaahyxuyjmeq172.png "/>
This article from "Liveyoung" blog, reproduced please contact the author!
Process communication (named pipe one-way communication)