java 使用 lsof 对“打开的文件过多”进行故障排除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15956452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Troubleshooting 'Too many files open' with lsof
提问by James Raitsev
I have a Java application running on Linux with PID 25426. When running lsof -p 25426
, I noticed:
我有一个在 Linux 上运行的 Java 应用程序,PID 为 25426。运行时lsof -p 25426
,我注意到:
java 25426 uid 420w FIFO 0,8 0t0 273664482 pipe
java 25426 uid 421r FIFO 0,8 0t0 273664483 pipe
java 25426 uid 461r FIFO 0,8 0t0 273622888 pipe
java 25426 uid 463w FIFO 0,8 0t0 273633139 pipe
java 25426 uid 464r FIFO 0,8 0t0 273633140 pipe
java 25426 uid 465r FIFO 0,8 0t0 273622889 pipe
java 25426 uid 471w FIFO 0,8 0t0 273623682 pipe
java 25426 uid 472r FIFO 0,8 0t0 273633141 pipe
How should this result be interpreted?
这个结果应该如何解释?
I am troubleshooting an issue with too many open files and trying to understand whether this observation is relevant.
我正在对打开文件过多的问题进行故障排除,并试图了解此观察结果是否相关。
As application continues to run, number of pipe
entries varies (goes up and down).
随着应用程序继续运行,pipe
条目数会发生变化(上升和下降)。
回答by Deepak Bala
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.
- 420w - 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.
- java- 打开文件的进程。
- 25426- 这应该是真正的 PID。如果不是,请通过发布标题让我们知道它是什么。
- 420w - 文件描述符编号后跟打开它的模式。(读/写)
- 0,8- 主要次要设备标识。
- 273664482- 文件的 inode。
- 管道- 在您的应用程序中打开的 FIFO 管道。
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 themor you can close them yourself.
您没有关闭所有流。有许多处于读或写模式的打开文件描述符正在写入未命名的管道。最常见的情况是,当人们使用Runtime.getRuntime.exec()然后继续保持与流程关联的流打开时。您可以使用 commons IO utils 库来关闭它们,也可以自己关闭它们。
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.
如果这不是问题,您需要深入研究代码库并确定泄漏流的位置并插入它们。