在Linux C语言中,使用pipe()函数创建一个匿名管道,以写文件形式写入数据,直到进程阻塞。最后一次输出的数据即为匿名管道最终的容量.

C语言源代码:

/* 功能:确定系统中对管道的缺省容量设置。 作者:幻竹涂 时间:2019年11月23日。 */

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
   
	int fd[2];
	if(pipe(fd)<0)   //创建一个匿名管道
	{
   
		perror("pipe");
		return -1;
	}
	int i = 0;
	while(write(fd[1],"a",1))//向管道中写入数据
	{
   
		i++;	
		printf("%04x ",i); //输出管道的容量
	}
	return 0;
}

运行实现结果

确认最后一次输出为10000H,即匿名管道容量为64kb。