/*first used pipe create pipe,then open and operate the pipe,last close pipe*/
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<string.h>
main()
{
//1.create pipe
mkfifo("p.pipe",0666);
//2.open pipe
int fd=open("p.pipe",O_RDWR);
//3.write content to pipe
char buf[30]={};
read(0,buf,30);
write(fd,buf,strlen(buf));
//4.close pipe
close(fd);
}
===========================================
/*another app can used the pipe by open the pipe of the same name above*/
/*default p.pipe be ceated on current directory*/
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
main()
{
//1.open pipe
int fd=open("p.pipe",O_RDWR);
//2.read content from pipe
char buf[30]={};
read(fd,buf,30);
printf("%s\n",buf);
//3.close pipe
close(fd);
}