问题出现的情况大概是这样的:我有一个多线程程序,每个线程是要fopen一个文件。当打开到第900+个的时候,程序突然异常退出,原因是fopen得到的为空,及不能再打开文件了。这是我查看了一下进程最大打开文件描述符数:ulimit -Sn ,值是1024。ulimit -Hn,值是4096。我就怀疑是这个1024限制了线程的打开文件数。接下来我就参照以下文档改这个值。

ile Descriptor Requirements (Linux Systems)

To ensure good server performance, the total number of client connections, database files, and log files must not exceed the maximum file descriptor limit on the operating system (ulimit -n). By default, the directory server allows an unlimited number of connections but is restricted by the file descriptor limit on the operating system. Linux systems limit the number of file descriptors that any one process may open to 1024 per process. (This condition is not a problem on Solaris machines, x86, x64, or SPARC).

After the directory server has exceeded the file descriptor limit of 1024 per process, any new process and worker threads will be blocked. For example, if the directory server attempts to open a Oracle® Berkeley JE database file when the operating system has exceeded the file descriptor limit, the directory server will no longer be able to open a connection that can lead to a corrupted database exception. Likewise, if you have a directory server that exceeds the file descriptor limit set by the operating system, the directory server can become unresponsive as the LDAP connection handler consumes all of the CPU's processing in attempting to open a new connection.

To fix this condition, set the maximum file descriptor limit per process on Linux machines.

To Increase the File Descriptor Limit (Linux)

Display the current hard limit of your machine.

The hard limit is the maximum server limit that can be set without tuning the kernel parameters in proc file system. $ ulimit -aH

core file size (blocks) unlimited

data seg size (kbytes) unlimited

file size (blocks) unlimited

max locked memory (kbytes) unlimited

max memory size (kbytes) unlimited

open files 1024

pipe size (512 bytes) 8

stack size (kbytes) unlimited

cpu time (seconds) unlimited

max user processes 4094

virtual memory (kbytes) unlimited

Edit the /etc/security/limits.conf and add the lines: * soft nofile 1000000

* hard nofile 1000000

Edit the /etc/pam.d/login by adding the line: session required /lib/security/pam_limits.so

Use the system file limit to increase the file descriptor limit to 65535.

The system file limit is set in /proc/sys/fs/file-max . echo 1000000> /proc/sys/fs/file-max

Use the ulimit command to set the file descriptor limit to the hard limit specified in/etc/security/limits.conf. ulimit -n 1000000

Restart your system.

reboot

再次查看unlimit -Sn ,值为1000000,unlimit -Hn,值为1000000.

再次跑我的程序的时候,顺利突破1000的大关。这会儿已经跑到2000+了也没出问题。

参考https://www.cnblogs.com/qq78292959/archive/2012/03/07/2383337.html。

参考https://blog.csdn.net/chinaclock/article/details/48346117?utm_source=blogkpcl8。

感谢这两位博主的无私奉献!

mysql打开的文件描述符限制_linux fopen个数限制的问题(文件描述符限制)相关推荐

  1. freopen函数的使用以及freopen与fopen的区别 open、fopen、freopen区别(文件操作)

    freopen函数的使用以及freopen与fopen的区别 https://www.cnblogs.com/hi3254014978/p/11450960.html freopen函数的使用:参见这 ...

  2. java套接字创建失败_Linux的文件描述符个数限制导致创建文件(或socket)失败的问题...

    众所周知,在相应进程的/proc/$pid/fd 目录下存放了此进程所有打开的fd.当然有些可能不是本进程自己打开的,如通过fork()从父进程继承而来的.本文着着重讲述socket有关的内容.当我们 ...

  3. 数据库-下载好的.sql文件如何用mysql打开

    数据库-下载好的.sql文件如何用mysql打开 登陆mysql 登陆mysql 以管理员模式运行命令行,登陆mysql: 将目录调整为sql的安装路径:如c:\mysql\mysql-8.0.17 ...

  4. MYSQL打开的文件数量太多

    在MYSQL数据库中,在分区表较多的情况下,经常发现下面的错误: 160317 17:04:14 [ERROR] Error in accept: Too many open files 处理这个问题 ...

  5. MySQL建表的限定于巨_Linux入门笔记(4/1/2016修改)

    本文笔记源自这里--[实验楼] 欢迎大家在下面交流其中有问题的地方喜欢请点收藏,每日更新(全部已亲自实践). 一. linux终端 1. 终端(Terminal)和控制台(Console)是有区别的: ...

  6. MySQL错误提示语句及翻译——详情请看我免费分享的文件

    一者.礼敬诸佛.二者.称赞如来.三者.广修供养.四者.忏悔业障.五者.随喜功德.六者.请转法輪.七者.请佛住世.八者.常随佛学.九者.恒顺众生.十者.普皆回向.添加链接描述 OS error code ...

  7. c# 指定打开某个路径下的CMD_Windows小技巧 批处理文件实现目录下文件批量打包压缩...

    最近整理资料,发现很多 pdf 文档,占用了不少的存储空间,考虑使用 7-zip 进行压缩存储,由于文件比较多,且分散在不同目录下,一个个文件压缩比较繁琐.为了提高效率且,方便后面取用,所有打算捣鼓个 ...

  8. linux文件移出目录命令_Linux 文件与目录管理详解

    一.目录树 在 Linux 底下,所有的文件与目录都是由根目录开始的. 根目录是所有目录与文件的源头,再一个一个的分支下来,有点像是树枝状. 因此,我们也称这种目录配置方式为:『目录树(directo ...

  9. mysql导出表结构_mysql导入导出表结构及表数据及执行sql文件

    从数据库导出数据库文件: 1.将数据库mydb导出到e:\MySQL\mydb.sql文件中: 打开开始->运行->输入cmd 进入命令行模式 c:\>MySQLdump -h lo ...

最新文章

  1. opencv meanStdDev
  2. 提高性能:用RequireJS优化Wijmo Web页面
  3. 有关域名方面的相关问题
  4. webpack 合并压缩_webpack的运用
  5. Qt学习笔记-使用shape() 使得碰撞更加精确
  6. PyTorch入门-自然语言分类任务
  7. PGM:贝叶斯网的参数估计
  8. SQL语句优化的30种方法,总结的太棒了
  9. C#/.Net 的托管堆和垃圾回收
  10. java中wint是什么意思,Java线程的同步演示代码,java线程演示,package Wint
  11. pycorrector 纠错工具安装
  12. 活性基因免疫靶向细胞疗法
  13. Android R- AudioManager之音量调节(一)
  14. 物流基础知识(十八)
  15. 六大维度层层剖析,一篇文章带你快速读懂信息无障碍
  16. webug靶场渗透基础攻略
  17. 稳了!工业质检蝉联第一
  18. SpringCloud 学习(一)---- 微服务的概念
  19. PluginOK中间件小程序家族不断壮大
  20. Linux中的sudoers没有root ALL=(ALL) ALL这一行

热门文章

  1. python查询数据库带逗号_浅谈pymysql查询语句中带有in时传递参数的问题
  2. lol服务器不稳定补偿地址,LOL9月4日更新bug补偿地址在哪里 9月4日更新bug补偿地址分享...
  3. iphone屏幕镜像如何全屏_苹果系统截屏录屏+标记剪辑功能详解( iPhone/iPad/Mac)
  4. Python中的驻留机制:小数据池和代码块
  5. 关于Python中if、for、with、list、dict的练习题
  6. Python正则表达式中问号的四种用法
  7. python中统计计数的几种方法
  8. Python Sphinx使用踩坑记录
  9. python与rpc服务
  10. mqtt消息推送 java_MQTT+ActiveMQ实现消息推送(服务器端java实现)