java程序中的文件描述符泄漏:打开的文件太多

发布于 2024-09-28 13:28:09 字数 426 浏览 0 评论 0原文

我有一个程序,其文件描述符不断增加。 我看到当我执行命令 ls -l /proc/5969/fd 时,其中 5969 是 java 程序的 pid,文件描述符的数量不断增加。 但我无法打开这些文件描述符之一来查看哪些文件保持打开状态: 这是列表的示例:

lrwx------ 1 root root 64 oct 24 16:08 52295 -> socket:[2577706264]
lrwx------ 1 root root 64 oct 24 16:08 52296 -> socket:[2579543392]
lrwx------ 1 root root 64 oct 24 16:08 52297 -> socket:[2578760962]

请帮助我找到一种方法来解决此文件描述符泄漏,了解哪些文件保持打开状态并增加文件描述符编号。

I have a program which suffer from file descriptor increasing.
I see when I execute the command ls -l /proc/5969/fd where 5969 is the pid of the java program the number of file descriptor continuously increasing.
but I am unable to open one of those files decriptors to see what file remains open :
here is an example of the listing :

lrwx------ 1 root root 64 oct 24 16:08 52295 -> socket:[2577706264]
lrwx------ 1 root root 64 oct 24 16:08 52296 -> socket:[2579543392]
lrwx------ 1 root root 64 oct 24 16:08 52297 -> socket:[2578760962]

Please help me finding a way to solve this file descriptor leak in knowing what files remains open and increase the file descriptor number.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-10-05 13:28:09

好吧,从快速观察来看,您在套接字上使用文件描述符,而不是文件。

在 UNIX 中,文件和套接字都使用文件描述符,因此您会遇到一个问题,即您没有关闭打开的套接字。

因此,您并没有让文件保持打开状态,而是实际上锁定了端口号,以防止其他程序使用。

Well, from a quick observation, you are using file descriptors on sockets, not files

In UNIX, both files and sockets use file descriptors, and so you have a problem where you are not closing sockets that you open.

As a result, you are not leaving a file open but are actually leaving port numbers locked from use by other programs.

○闲身 2024-10-05 13:28:09

Try

# lsof -p <pid>

将列出按进程 ID 打开的所有“文件”,可能会显示套接字绑定到的 IP/端口。如果您的程序是客户端,您可能会被 TCP RST 断开连接并且无法正确清理文件描述符。

Try

# lsof -p <pid>

will list all 'files' open by process id, may show you the ip/port the socket was bound to. If your program is client side, youre probably getting disconnected by TCP RST and not cleaning up the file descriptor properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文