zoukankan      html  css  js  c++  java
  • 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
    

      


     

  • 相关阅读:
    7.16PHP所学知识总结
    7.13PHP所学知识总结
    7.11PHP所学知识总结
    2018.08.07jQuery实现焦点轮播图
    2018.07.30js实现轮播图
    2018.07.27javaScript中的DOM操作
    2018.07.23冒泡排序
    2018.07.22 数组
    2018.07.20break和continue的区别
    2018.07.18if条件语句swich条件语句
  • 原文地址:https://www.cnblogs.com/morganh/p/8447041.html
Copyright © 2011-2022 走看看