- 论坛徽章:
- 0
|
pipe设备:实现一个循环缓冲区阻塞读写
pipe0为设备节点
应用程序:
int main(int argc, char **argv)
{
int fd;
int err;
char wb[1000] = "today is good day!";
char wb1[1000] = "what's the problem";
char rb[1000] ;
fd = open("/dev/pipe0", O_RDWR);//读写打开设备
if (fd < 0)
{
printf("can't open!\n");
}
printf("fd is : %d\n ",fd);
printf("%s\n", wb);
printf("%s\n", wb1);
write(fd, &wb, 20);//写二次
write(fd, &wb1, 20);
err=read(fd, &rb, 20);//读数据
printf("err is :%d\n", err);
printf("%s\n", rb);//打印所读到数据
return 0;
}
应用程序Linux下运行结果:
root@book-desktop:/work/pipe# ./pipetest
fd is : 3
today is good day!
what's the problem
err is :20
today is good day!
root@book-desktop:/work/pipe#
root@book-desktop:/work/pipe#
root@book-desktop:/work/pipe# cat /dev/pipe0
^C
root@book-desktop:/work/pipe#
cat pipe0怎么什么都没有,是无数据还是阻塞,为什么?求大神讲解下cat的机制啊? |
|