在需要用FIFO的时候,特别是读取端是第三方开源组件的时候(一般第三方开源组件默认都支持文件加载数据的方式比如ffmpeg),有名管道就特别方便。今天测试了缓存大小实测应该是64K,
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
int main(int argc, char **argv){
const char *file_fifo = "./fifo";
if (-1 == mkfifo(file_fifo,0777)){
printf("creat fifo err \n");
return false;
}
int fd =open(file_fifo,O_WRONLY);
if (fd == -1)
{
printf("open fifo file err \n");
return false;
}
int write_len = 0;
int buffer_len = 0;
int total_len = 0;
char buffer[] = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
while (true)
{
if((write_len = write(fd, buffer, strlen(buffer))) != strlen(buffer)) {
close(fd);
printf("write error, exit total %d\n", total_len);
return false;
}
total_len += write_len;
printf("write ok, total %d\n", total_len);
}
return true;
}
ulimit -a 看到的pipe_size指的应该是一次原子写入的大小
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 14743
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited