3

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
zacky
  • 31
  • 1
  • 2

2 Answers2

5

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.

riwalk
  • 14,033
  • 6
  • 51
  • 68
  • 1
    It is not *just* the port numbers that he is tying down. In UNIX / Linux, a process is only allowed to have a certain number of fd's (file descriptors) open, be they file fd's, socket fd's, pipe fd's or whatever. – Stephen C Oct 24 '10 at 22:56
  • I am not sure I am using socket and that I have port numbers locked. – zacky Oct 26 '10 at 00:06
  • do you know a way to see what are the open files remaining open to see where I let things open? – zacky Oct 26 '10 at 00:07
  • @zacky, you need to read my post. **There are no files open**. Whether you are using a 3rd party library or whether you are doing any network programming, the fact remains that based on what you posted, **there are no files open**. – riwalk Oct 26 '10 at 16:43
  • ok but if you are telling me that the open files are sockets and not files so how can I see what socket url it is? I need to understand where my program is leaking – zacky Oct 29 '10 at 13:27
  • 1
    @zacky, research unix sockets. Please. They operate on ports, not URLs. You have everything you need to find the answer. – riwalk Oct 29 '10 at 15:26
  • ok so a turnaround would be to have a command to close all open open sockets. is there a command in ubuntu for this? – zacky Nov 02 '10 at 10:04
5

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.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
krisso
  • 51
  • 1