一、测试源码
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
int sum = 0;
close(0);
close(2);
while(open(argv[1], O_RDONLY) != -1)
{
sum++;
}
printf("sum = %d\n",sum);
return 0;
}
二、测试结果
因为在文件IO中,0 1 2 已经分别被标准输入 标准输出 标准出错占用,所以最大为1024个。