//send.c 发送端
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int fd, n;
char pbuf[20] = {0};
FILE *fp;
if(argc != 2){
perror("Usage: a.out ");
exit(1);
}
if(!(fp = fopen(argv[1], "r"))){
printf("can't open %s", argv[1]);
exit(1);
}
if((mkfifo("my_fifo", O_CREAT|O_RDWR|0666)) < 0) {
perror("mkfifo");
exit(1);
}
if((fd = open("my_fifo" , O_WRONLY)) < 0) {
perror("open");
exit(1);
}
while(fgets(pbuf, sizeof(pbuf), fp) != NULL){ n = strlen(pbuf);
if(write(fd, pbuf, n) != n)
perror("write error to pipe");
}
fclose(fp);
return 0;
}
//recv.c 接收端
#include