File Descriptor Leak

https://martin-ueding.de/articles/c-file-descriptors/index.html

http://blog.sina.com.cn/s/blog_605f5b4f01013lgv.html  (good)

https://docs.oracle.com/cd/E23095_01/Platform.93/ATGInstallGuide/html/s0607detectingfiledescriptorleaks01.html

https://mahaveerdarade.wordpress.com/2013/12/03/finding-fd-leak-with-valgrind/

http://blog.csdn.net/fenfeiqinjian/article/details/51067048

 

Detecting File Descriptor Leak

 It is important to ensure that files that are opened always get closed. Failing to close files can result in file descriptor leaks. You can detect a file descriptor leak in two different ways:

  • You may notice a lot of IOExceptions with the message “Too many open files.”

  • During load testing, you periodically run a profiling script, such as lsof (on UNIX), and you notice that the list of file descriptors grows continually.

File descriptor leaks can also lead to a variety of failures on attempts to open properties files, sockets, etc. If your error log contains a lot of chaotic-looking error messages, the presence of a file descriptor leak is one thing to check.

 

Test:https://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html

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

 

Reference: 

https://www.cnblogs.com/wangkangluo1/archive/2012/04/18/2454916.html

# lsof -a -u pkrumins -c bash

-a参数可以将多个选项的组合条件由或变为与,上面的命令会显示所有由pkrumins用户以及bash进程打开的文件。

 

 

$ cat test.sh
# check the pid
#!/bin/sh
echo "">total_handler

# use way1
psid=`ps -ef|grep $1|head -1|awk '{print $2}'`
echo $psid
#or way2 
psid=`pidof $1`
echo $psid

  

 

#!/bin/sh
echo "">total_handler
psid=`ps -ef|grep $1|head -1|awk '{print $2}'`
count=0
while [ $count -lt 3000 ]
do
 lsof -p $psid|wc -l >> total_handler
 sleep 10
count=`expr $count + 1`
done

  


 

转载于:https://www.cnblogs.com/morganh/p/8447041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值