“Too many open files” 小记
pycharm远程链接centos7开发过程中突然遇到“Too many open files”。
几点记录:
1. 命令:ulimit -n
查看系统配置,其中的
open files (-n)
表示每个进程最多能打开8192个文件句柄(是句柄数,socket连接也算在里面)。如果单个进程打开的文件句柄数量超过了系统定义的值,就会提到“too many files open”的错误提示。
2. cat /proc/sys/fs/file-max
查看系统允许打开的文件句柄的最大数量。
3. cat /proc/sys/fs/file-nr
查看已经打开的句柄数,转载如下:
[root@hostname ~]# cat /proc/sys/fs/file-nr
53536 0
| | |
| | |
| | maximum open file descriptors
| total free allocated file descriptors
total allocated file descriptors
(the number of file descriptors allocated since boot)
不知道总的句柄数超过了系统限制会不会报同一个错。
4. lsof -n|awk '{print $2}'|sort|uniq -c |sort -nr
使用lsof查看打开的文件,这条命令统计了每个进程打开了多少个文件。
但是,lsof的统计的范围过于广泛。
What is an open file? Is an open file a file that is being used, or is it an open file descriptor? A file descriptor is a data structure used by a program to get a handle on a file, the most well know being ,, for standard in, standard out, and standard error. The file-max kernel parameter refers to open file descriptors, and file-nr gives us the current number of open file descriptors. But lsof lists all open files, including files which are not using file descriptors – such as current working directories, memory mapped library files, and executable text files. To illustrate, let’s examine the difference between the output of lsof for a given pid and the file descriptors listed for that pid in /proc.
--------------------------------
Some of the open files which are not using file descriptors: library files, the program itself (executable text), and so on as listed above. These files are accounted for elsewhere in the kernel data structures (cat /proc/PID/maps to see the libraries, for instance), but they are not using file descriptors and therefore do not exhaust the kernel’s file descriptor maximum.
5. ls -l /proc/175072/fd/
使用/proc/下的信息是最准确的,写了一个脚本统计<username>用户的进程打开的文件句柄数的排序:
#!/usr/bin/perl use strict;
use Data::Dumper; my @pids = `ps aux | grep ^username | awk '{print \$2}'`;
my $res = []; foreach my $pid (@pids) {
$pid =~ s/\n//; my $fds = `ls /proc/$pid/fd/ | wc -l`;
$fds =~ s/\n//; push(@$res, {pid => $pid, fd => $fds});
} $res = [ sort { $b->{fd} <=> $a->{fd} } @$res];
foreach my $val (@$res) {
print "$val->{pid}:$val->{fd}\n";
}
ref.
http://www.jb51.net/article/97706.htm
https://stackoverflow.com/questions/21999820/what-are-the-number-of-open-files-for-a-user-on-linux-and-system-wide-for-linux
https://unix.stackexchange.com/questions/66235/how-to-display-open-file-descriptors-but-not-using-lsof-command
https://www.netadmintools.com/art295.html
“Too many open files” 小记的更多相关文章
- Git小记
Git简~介 Git是一个分布式版本控制系统,其他的版本控制系统我只用过SVN,但用的时间不长.大家都知道,分布式的好处多多,而且分布式已经包含了集中式的几乎所有功能.Linus创造Git的传奇经历就 ...
- linux 下cmake 编译 ,调用,调试 poco 1.6.0 小记
上篇文章 小记了: 关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记. http://www.cnblogs.com/bleachli/p/4352 ...
- Cocos2d-x项目移植到WinRT/Win8小记
Cocos2d-x项目移植到WinRT/Win8小记 作者: K.C. 日期: 11/17/2013 Date: 2013-11-17 23:33 Title: Cocos2d-x项目移植到WinRT ...
- xcode6制作IOS .a静态库小记
xcode6制作IOS .a静态库小记 创建iOS静态库 简单写个打印的代码 编码完成之后,直接Run就能成功生成.a文件了,选择 xCode->Window->Organizer-> ...
- Python cx_Oracle 安装小记
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python cx_Oracle 安装小记 SQLAlchemy 是 Pytho ...
- 使用Maven自动部署Java Web项目到Tomcat问题小记
导读 首先说说自己为啥要用maven管理项目,一个直接的原因是:我在自己电脑上开发web项目,每次部署到服务器上时都要经历如下步骤: 首先在Eclipse里将项目打包成war包 将服务器上原来的项目文 ...
- RHEL 7 下内存管理小记
RHEL 7 下内存管理小记 一.Overview 众所周知,在 Linux 操作系统中有三个目录非常有趣好玩. /dev /run /proc 一个个解释下,/dev 用于对特殊设备(BTW:特殊设 ...
- Cnblog页面美化小记
Cnblog页面美化小记 这两天我在网上翻找了许许多多的资料,打开了不计其数的博客,对着\(js\).\(html\).\(css\)等文件删删改改,在浏览器和\(vscode\)间辗转腾挪...总算 ...
- Sass 主要知识点小记
Sass 主要知识点小记 以前写样式的时候,每个元素的颜色,背景色都需要重新写一遍,然后就想CSS难道没有变量么?最后就查到Sass.但当时没有静下心来好好的看一下,今天正好有时间,就在这里边看边整理 ...
随机推荐
- Python并行编程(九):线程通讯queue
1.基本概念 当线程之间要共享资源或数据的时候,可能变的非常复杂.Python的threading模块提供了很多同步原语,包括信号量,条件变量,事件和锁.如果可以使用这些原语的话,应该优先考虑使用这些 ...
- Jersey 出现415 MediaType is not supported问题的原因
前段时间在使用jersey的时候,经常碰到这个问题,一直没有找到真正的原因.找了其他的解决访问,比如使用jackson以及手动转为json再返回给前端. 后续发现问题出在domain对象属性类型和se ...
- 013-HQL中级3-Hive四种数据导入方式介绍
Hive的几种常见的数据导入方式这里介绍四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询出相应的数据并导入到Hive表中:(4).在 ...
- 登录plsql 报错 the account is locked --用户被锁
登录数据库服务器,进入oracle用户下: [root@uumsnormal-oracle admin]# su - oracle [oracle@uumsnormal-oracle ~]$ sqlp ...
- 深入跟踪MFC程序的执行流程
来源: http://blog.csdn.net/ljianhui/article/details/8781991 在MFC程序设计的学习过程中最令人感到难受,甚至于有时会动摇学习者信心的就是一种对于 ...
- 搭建 maven 项目 搭建 maven web 项目及遇到 JDK 的问题
临时起意搭建一个 maven web 项目.使用的servlet 3.0 及 1.8 JDK. maven 默认创建了一个JDK 1.5 版本的项目. 注意此处选择一下WAR包.不然在配置中配置的话会 ...
- 在Idea中连接数据库并生成实体类(mybatis逆向生成实体类)
1.连接数据库 (1)按下图 , 点击view-----选择tool windows----------选择database并点击 (2)弹出Database窗口 点击加号------------选 ...
- Druid出现DruidDataSource - recyle error - recyle error java.lang.InterruptedException: null异常排查与解决
一.问题回顾 线上的代码之前运行的都很平稳,突然就出现了一个很奇怪的问题,看错误信息是第三方框架Druid报出来了,连接池回收连接时出现的问题. 2018-05-14 20:01:32.810 ERR ...
- sgu 100 A+B 解题报告及测试数据
100.A+B time limit per test: 0.25 sec. memory limit per test: 65536 KB 题解:上手题,不解释. 直接上代码: #include & ...
- Spring AOP (事务管理)
一.声明式事务管理的概括 声明式事务(declarative transaction management)是Spring提供的对程序事务管理的方式之一. Spring的声明式事务顾名思义就是采用声明 ...