简体   繁体   English

Java程序中的文件描述符泄漏:打开文件过多

[英]file descriptor leak in java program : too many open files

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. 我看到当我执行命令ls -l / proc / 5969 / fd时,其中5969是Java程序的pid,文件描述符的数量不断增加。 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. 请帮助我找到解决此文件描述符泄漏的方法,以了解哪些文件保持打开状态并增加文件描述符数目。

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. 在UNIX中,文件和套接字都使用文件描述符,因此在不关闭打开的套接字时会遇到问题。

As a result, you are not leaving a file open but are actually leaving port numbers locked from use by other programs. 如此一来,您不会打开文件,而是实际上使端口号被锁定,以防止其他程序使用。

Try 尝试

# lsof -p <pid>

will list all 'files' open by process id, may show you the ip/port the socket was bound to. 将按进程ID列出所有打开的“文件”,并可能显示套接字绑定到的IP /端口。 If your program is client side, youre probably getting disconnected by TCP RST and not cleaning up the file descriptor properly. 如果您的程序是客户端程序,则您可能会被TCP RST断开连接,并且无法正确清理文件描述符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM