0

I am using a legacy lib in Perl which is leaking file descriptors (I don't have access to the C source)

I know the name of the file the code is opening, but I don't know the file descriptor. Is there any way I can determine the file descriptor so I can close it?

OneSolitaryNoob
  • 5,423
  • 3
  • 25
  • 43

1 Answers1

4

/proc/<pid>/fd has the file descriptors.

$ ls -l /proc/$$/fd
total 0
lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 0 -> /dev/pts/3
lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 1 -> /dev/pts/3
lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 2 -> /dev/pts/3
lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 255 -> /dev/pts/3

You can also try lsof -a -p <pid>.

$ lsof -a -p $$
lsof: WARNING: can't stat() debugfs file system /sys/kernel/debug
      Output information may be incomplete.
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF        NODE NAME
bash    13841 ikegami  cwd    DIR   8,17     4096 12884902307 /home/ikegami
bash    13841 ikegami  rtd    DIR    8,1     4096           2 /
bash    13841 ikegami  txt    REG    8,1   959120      130675 /bin/bash
bash    13841 ikegami  mem    REG    8,1    52120      914147 /lib/x86_64-linux-gnu/libnss_files-2.15.so
bash    13841 ikegami  mem    REG    8,1    47680      914446 /lib/x86_64-linux-gnu/libnss_nis-2.15.so
bash    13841 ikegami  mem    REG    8,1    97248      914458 /lib/x86_64-linux-gnu/libnsl-2.15.so
bash    13841 ikegami  mem    REG    8,1    35680      914035 /lib/x86_64-linux-gnu/libnss_compat-2.15.so
bash    13841 ikegami  mem    REG    8,1  1811128      914019 /lib/x86_64-linux-gnu/libc-2.15.so
bash    13841 ikegami  mem    REG    8,1    14768      914453 /lib/x86_64-linux-gnu/libdl-2.15.so
bash    13841 ikegami  mem    REG    8,1   159200      914028 /lib/x86_64-linux-gnu/libtinfo.so.5.9
bash    13841 ikegami  mem    REG    8,1   149280      914450 /lib/x86_64-linux-gnu/ld-2.15.so
bash    13841 ikegami    0u   CHR  136,3      0t0           6 /dev/pts/3
bash    13841 ikegami    1u   CHR  136,3      0t0           6 /dev/pts/3
bash    13841 ikegami    2u   CHR  136,3      0t0           6 /dev/pts/3
bash    13841 ikegami  255u   CHR  136,3      0t0           6 /dev/pts/3
ikegami
  • 367,544
  • 15
  • 269
  • 518
jim mcnamara
  • 16,005
  • 2
  • 34
  • 51