//********* pipe read ****************
#include
#include
#include
#include
#include
#include
#include
#define FIFO "/tmp/myfifo"
void main()
{
char buf_r[100]={0};
int fd, r_num;
if(mkfifo(FIFO,O_CREAT|O_EXCL)<0&&(errno!=EEXIST))
printf("connt create fifoServer! \n");
fd=open(FIFO, O_RDONLY,0);
if(fd<0)
{
printf("open FIFO error \n");
exit(1);
}
while(1)
{
r_num=read(fd, buf_r,100);
if(r_num>0)
printf("r_num= %d buf_r=%s \n",r_num,buf_r);
if(buf_r[0]=='Q')
{
close(fd);
exit(0);
}
}
}
//********* pipe write ****************
#include
#include
#include
#include
#include
#include
#include
#include
#define FIFO "/tmp/myfifo"
void main()
{
char buf_w[100]={0};
int fd;
//if(mkfifo(FIFO,O_CREAT|O_EXCL)<0&&(errno!=EEXIST))
// printf("can not create fifoserver! \n");
fd=open("/tmp/myfifo",O_WRONLY|O_NONBLOCK,0);
if(fd<0)
{
printf("open FIFO error! fd=%d\n",fd);
exit(1);
}
while(1)
{
printf("please input info:");
scanf("%s",buf_w);
if(write(fd,buf_w,strlen(buf_w)) ==-1)
{
close(fd);
exit(1);
}
if(buf_w[0]=='Q')
{
close(fd);
exit(0);
}
}
}
pipe.rar
阅读(1572) | 评论(0) | 转发(0) |