博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux: Find Out How Many File Descriptors Are Being Used
阅读量:4285 次
发布时间:2019-05-27

本文共 2717 字,大约阅读时间需要 9 分钟。

轉載自 

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

 

 

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 = 1020	0	70000

Where,

  1. 1020 The number of allocated file handles.
  2. 0 The number of unused-but-allocated file handles.
  3. 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  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:

  • I also recommend reading /proc file system related document, and lsof man page to get a better understanding about fd and files.

转载地址:http://awpgi.baihongyu.com/

你可能感兴趣的文章
vector length_error
查看>>
Shell脚本处理浮点数的运算和比较实例
查看>>
bash shell for循环1到100
查看>>
latex中长公式换行,很好的办法
查看>>
nohup命令
查看>>
make 操作技巧指南--gcc版本设置
查看>>
sort和sortrows对矩阵排序
查看>>
matlab专区--------------matlab里面如何保留小数特定位数
查看>>
Matlab 绘图坐标轴刻度设置小数位数
查看>>
Matlab 条形图绘制 以及 添加误差棒 改变条形图形状
查看>>
cmake基本用法
查看>>
matlab 增加或减少图例 legend 线的长度
查看>>
matlab:把cell中的某个元素删去
查看>>
matlab 集合运算 交集 并集 差集
查看>>
C++ 给vector去重的三种方法
查看>>
map的详细用法
查看>>
C++初始化函数列表
查看>>
STL各种排序
查看>>
#include<map>
查看>>
z字形扫描
查看>>