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

  


 

posted on 2018-02-13 17:16  cdekelon  阅读(214)  评论(0编辑  收藏  举报

导航