Troubleshooting 'Too many files open' with lsof

后端 未结 1 1533
天命终不由人
天命终不由人 2021-02-04 12:15

I have a Java application running on Linux with PID 25426. When running lsof -p 25426, I noticed:

java    25426 uid  420w  FIFO                0,8           


        
1条回答
  •  一个人的身影
    2021-02-04 12:38

    Definition

    • java - The process with the open file.
    • 25426 - This should be the real PID. If not please let us know what it is by posting the header.
    • 420 w - The file descriptor number followed by the mode it was opened with. (Read / write)
    • 0,8 - Major minor device identification.
    • 273664482 - The inode of the file.
    • pipe - A FIFO pipe that is open in your application.

    Interpretation

    You are not closing all your streams. There are many open file descriptors in read or write mode that are writing to un-named pipes. The most common scenario for this to happen, is when folks use Runtime.getRuntime.exec() and then proceed to keep the streams associated with the process open. You can use the commons IO utils library to close them or you can close them yourself.

        try
        {
            p = Runtime.getRuntime().exec("something");
        }
        finally
        {
            if (p != null)
            {
                IOUtils.closeQuietly(p.getOutputStream());
                IOUtils.closeQuietly(p.getInputStream());
                IOUtils.closeQuietly(p.getErrorStream());
            }
        }
    

    If that is not the problem, you'll need to dig into your code base and identify where the leaky streams are and plug them.

    0 讨论(0)
提交回复
热议问题