请教fopen能够同时打开的文件数上限
时间:2010-07-30
来源:互联网
我想知道在Linux、HP-Unix、Aix、Solaris等平台下,常见编译器实现的fopen能够同时打开的文件数上限。在相应的平台上,是否有系统设置或者编译器提供的函数可以被用来调整这个上限值。
比如,Windows下VC9实现的fopen默认能够最大打开512个文件,但可以通过_setmaxstdio函数设置其上限达到2048。对于其它平台及其上的编译器,由于没有相关平台可供测试,也没有相关的经验,故请教大家。
下面有一段测试代码:
复制代码
比如,Windows下VC9实现的fopen默认能够最大打开512个文件,但可以通过_setmaxstdio函数设置其上限达到2048。对于其它平台及其上的编译器,由于没有相关平台可供测试,也没有相关的经验,故请教大家。
下面有一段测试代码:
- #include <iostream>
- #include <cstdio>
- #include <cstring>
-
- using namespace std;
-
- int main()
- {
- int count = 0;
-
- for (;;)
- {
- char buf[256];
- sprintf(buf, "logs\\log_%d.txt", ++count);
- FILE *pFile = fopen(buf, "a+");
- if (pFile == NULL)
- {
- cout << "Failed to create the file \"" << buf << "\"\n";
- cout << "Error msg: " << strerror(errno) << endl;
- break;
- }
- else
- {
- fprintf(pFile, "a line for test\n");
- cout << "Created a file, No." << count << endl;
- }
- }
- }
作者: tyc611 发布时间: 2010-07-30
ulimit -n
作者: hellioncu 发布时间: 2010-07-30
回复 tyc611
复制代码
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <sys/param.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- #ifdef OPEN_MAX
- static long openmax = OPEN_MAX;
- #else
- static long openmax = 0;
- #endif
- #define OPEN_MAX_GUESS 1024
- int main( int argc, char *argv[] )
- {
- if( openmax == 0 ) { // Run sysconf to determine the value
- errno = 0;
- if( ( openmax = sysconf( _SC_OPEN_MAX ) ) < 0 ) {
- if( errno == 0 ) {
- openmax = OPEN_MAX_GUESS;
- } else
- printf( "sysconf error" );
- }
- }
- printf( "%ld\n", openmax );
- return 0;
- }
作者: churchmice 发布时间: 2010-07-30
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28