我使用命令:ulimit -n 并获取数字 1024,这是我的系统中每个进程打开文件的最大数量。但是通过以下程序我取数字 510...?怎么了
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
int main( void )
{
int pipe_ext = 0, pfd[ 2 ], counter = 0;
while ( 1 )
{
pipe_ext = pipe( pfd );
//errno = 0;
if ( pipe_ext == 0 )
{
write( pfd[ 1 ], "R", 1 );
counter = counter + 1;
printf("Counter = %d\n", counter );
}
else
{
perror( "pipe()" );
printf("errno = %d\n", errno );
exit( 1 );
}
}
return( 0 );
}
最佳答案
这里没有问题。
管道有两端,每一端都有自己的文件描述符。
因此,管道
的每一端都算作一个超出限制的文件。
1024/2 = 512 和 510 之间的细微差别是因为您的进程已经打开了文件 stdin、stdout 和 stderr,这会影响限制。
关于linux - Linux 中每个进程的最大打开文件数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30108288/