4

I have a program that quits after a time with "too many open files". How can I trace which files are opened and closed? I know I can set this limit a higher value, but that would only defer the problem.

I remember using a program like dtruss or dtrace for that purpose but I can't remember how I invoked it and --help gave to much confusion.

I run that program with a wrapper script based on nodejs, so I need to follow the child processes.

Question: what is the best strategy to find out which files (descriptors) are opened and which are closed?

2
  • Can you give some more details about the actual program?
    – Gerry
    Commented May 10, 2012 at 17:35
  • It is based on TeX (LuaTeX). I use the wrapper script "start.js" that starts TeX. My program loads images and probably doesn't close 'em. And I'd like to like to "trace" the opening/closing of external files.
    – topskip
    Commented May 10, 2012 at 20:13

1 Answer 1

2

lsof will show you the open file handles.

If you know the PID use the -p flag.

Eg, on my zsh shell at the moment I see:

alex@smiley:~|⇒  lsof -p 82946
COMMAND   PID USER   FD   TYPE DEVICE  SIZE/OFF     NODE NAME
zsh     82946 alex  cwd    DIR  14,12      2414   186278 /Users/alex
zsh     82946 alex  txt    REG  14,12   1103984       73 /bin/zsh
zsh     82946 alex  txt    REG  14,12    474672   787843 /usr/lib/zsh/4.3.11/zsh/zle.so
zsh     82946 alex  txt    REG  14,12    258672   787864 /usr/lib/zsh/4.3.11/zsh/complete.so
zsh     82946 alex  txt    REG  14,12    120576   787863 /usr/lib/zsh/4.3.11/zsh/complist.so
zsh     82946 alex  txt    REG  14,12     71264   787838 /usr/lib/zsh/4.3.11/zsh/zutil.so
zsh     82946 alex  txt    REG  14,12     79968   787852 /usr/lib/zsh/4.3.11/zsh/parameter.so
zsh     82946 alex  txt    REG  14,12    599280  7719861 /usr/lib/dyld
zsh     82946 alex  txt    REG  14,12 296980480 12427083 /private/var/db/dyld/dyld_shared_cache_x86_64
zsh     82946 alex    0u   CHR   16,0   0t26354     6285 /dev/ttys000
zsh     82946 alex    1u   CHR   16,0   0t26354     6285 /dev/ttys000
zsh     82946 alex    2u   CHR   16,0   0t26354     6285 /dev/ttys000
zsh     82946 alex   10u   CHR   16,0    0t3432     6285 /dev/ttys000

The Type column shows the various file or pseudo file types that might be open, sockets, pipes, etc.

ulimit or limit, depending on system and shell lets you change the number of open files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .