赞
踩
1.首先创建fifo
linux命令:mkfifo a.fifo
写程序
fifo_size.c:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
char buf[4096] = {0};
int n, i = 0;
int fd = open(“/a.fifo”, O_RDWR);
printf("time\t\t seq\t write\t total \n");
while (1) {
int ret = write(fd, buf, sizeof(buf));
if (ret >= 0)
n += ret;
else
break;
printf("%u \t%d \t%d \t%d \n", time(NULL), i++, ret, n);
}
return 0;
}
gcc -o fifo_size fifo_size.c
[hxwang@localhost ~]$ ./fifo_size
time seq write total
1656583502 0 4096 4096
1656583502 1 4096 8192
1656583502 2 4096 12288
1656583502 3 4096 16384
1656583502 4 4096 20480
1656583502 5 4096 24576
1656583502 6 4096 28672
1656583502 7 4096 32768
1656583502 8 4096 36864
1656583502 9 4096 40960
1656583502 10 4096 45056
1656583502 11 4096 49152
1656583502 12 4096 53248
1656583502 13 4096 57344
1656583502 14 4096 61440
1656583502 15 4096 65536
可见fifo最大缓存是65536
写入65536 字节后,写入进程阻塞了
读程序
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(){
char buf[4096] = {0};
int n, i = 0;
int fd = open(“a.fifo”, O_RDWR);
read(fd, buf, 1024);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。