Find Out How Many File Descriptors Are Being Used
来源:互联网 发布:怎么复制淘宝店铺装修 编辑:程序博客网 时间:2024/05/20 20:05
Linux: Find Out How Many File Descriptors Are Being Used
While administrating a box, you may wanted to find out what a processes is doing and find out how many file descriptors (fd) are being used. You will surprised to find out that process does open all sort of files:
=> Actual log file
=> /dev files
=> UNIX Sockets
=> Network sockets
=> Library files /lib /lib64
=> Executables and other programs etc
In this quick post, I will explain how to to count how many file descriptors are currently in use on your Linux server system.
Step # 1 Find Out PID
To find out PID for mysqld process, enter:# ps aux | grep mysqld
OR# pidof mysqld
Output:
28290
Step # 2 List File Opened By a PID # 28290
Use the lsof command or /proc/$PID/ file system to display open fds (file descriptors), run:# lsof -p 28290
# lsof -a -p 28290
OR# cd /proc/28290/fd
# ls -l | less
You can count open file, enter:# ls -l | wc -l
Tip: Count All Open File Handles
To count the number of open file handles of any sort, type the following command:# lsof | wc -l
Sample outputs:
5436
List File Descriptors in Kernel Memory
Type the following command:# sysctl fs.file-nr
Sample outputs:
fs.file-nr = 1020070000
Where,
- 1020 The number of allocated file handles.
- 0 The number of unused-but-allocated file handles.
- 70000 The system-wide maximum number of file handles.
You can use the following to find out or set the system-wide maximum number of file handles:# sysctl fs.file-max
Sample outputs:
fs.file-max = 70000
See how to set the system-wide maximum number of file handles under Linux for more information.
More about /proc/PID/file & procfs File System
/proc (or procfs) is a pseudo-file system that it is dynamically generated after each reboot. It is used to access kernel information. procfs is also used by Solaris, BSD, AIX and other UNIX like operating systems. Now, you know how many file descriptors are being used by a process. You will find more interesting stuff in /proc/$PID/file directory:
- /proc/PID/cmdline : process arguments
- /proc/PID/cwd : process current working directory (symlink)
- /proc/PID/exe : path to actual process executable file (symlink)
- /proc/PID/environ : environment used by process
- /proc/PID/root : the root path as seen by the process. For most processes this will be a link to / unless the process is running in a chroot jail.
- /proc/PID/status : basic information about a process including its run state and memory usage.
- /proc/PID/task : hard links to any tasks that have been started by this (the parent) process.
See also: /proc related FAQ/Tips
/proc is an essentials file system for sys-admin work. Just browser through our previous article to get more information about /proc file system:
参考
http://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html
- Find Out How Many File Descriptors Are Being Used
- How is jstack being used to find the bottlenect of a java program
- how to find the corresponding libraries are linked to when some APIs are used(2.0)
- how to find the corresponding libraries are linked to when some APIs are used(3.0)
- How Are Character Sets Used?
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- How Many Paths Are There
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- The Swift Pods being used are: Box, ReactiveCocoa, and Result
- openmp--test how many threads used
- How are bloom filters used in HBase?
- How are bloom filters used in HBase?
- Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how man
- HDU 3038 How Many Answers Are Wrong
- HDU 3038 How Many Answers Are Wrong
- NoSuchMethodException
- 使用重复键插入到bst树中
- string::npos
- [算法]游戏'数读’的基本解法 JAVA版。
- 关于Netty Pipeline中Handler的执行顺序问题
- Find Out How Many File Descriptors Are Being Used
- 2014最受欢迎的8款免费PSD线框图工具
- 快速USB学习
- 就是从房价开始的开发时间了咖啡吉欧斯偶然防水外壳
- Java设计模式---中介者模式
- js 调用百度地图api,并在地图上进行打点,添加标注
- android图标的一些知识
- MyEclipse SVN插件冲突导致不能使用解决办法
- 如何将只能放在控制面板中的portlet加入到普通的站点页面中