每个进程默认最多打开1024个文件。
每个进程的fd是不相同的:
进程A fd=3;与进程B中fd=3;所打开的文件不相同。
下面是用于测试每个进程最多打开多少文件。
#include<stdio.h>
#include<unistd.h>#include<fcntl.h>
#include<errno.h>
#include<string.h>
int main()
{
int fd;
int max= 1;
fd = open("hello",O_RDONLY);
printf("%d\n",fd);
while(max>0)
{
ret = open("hello",O_RDONLY);
if(fd<0)
{
printf("err:%d,%s\n",errno,strerror(errno));
}
printf("%d\n",max);
}
printf("*************\n");
fd = open("hello",O_RDONLY);
printf("%d\n",fd);
while(1);
close(fd);
}
本文提供了一段C代码,用于测试单个进程能够打开的最大文件数量,默认限制为1024个。通过循环尝试打开同一文件直至失败,来确定实际的限制值。

被折叠的 条评论
为什么被折叠?



