每个进程的FD

每个进程默认最多打开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);
}

猜你喜欢

转载自blog.csdn.net/qq_14814909/article/details/80828921
fd
今日推荐