how to see how many open file descriptors my program has?

  • Thread starter Rex Gustavus Adolphus
  • Start date
R

Rex Gustavus Adolphus

This question is about a pre-5.6-perl


I have a problem with a deamon-program I've written that after a
couple of days/weeks runs out of file descriptors.

I wonder if there is a command
to see how many open file descriptors my program has?

And is there a command
to see how many open file descriptors the system has?

I am not opening them explicitly,
I think they are being opened by
glob() and/or File::Copy::move
(the deamon is polling for certain files, and when found
moves them between NFS-mounted filesystems)

tia
/RGA
 
P

pkent

I have a problem with a deamon-program I've written that after a
couple of days/weeks runs out of file descriptors.

I wonder if there is a command
to see how many open file descriptors my program has?

And is there a command
to see how many open file descriptors the system has?

The ulimit command might be of use in raising the limit, although that
doesn't really solve the problem.
I am not opening them explicitly,
I think they are being opened by
glob() and/or File::Copy::move

Interesting - I'd have thought that these wouldn't leak filehandles...
One thing that I've seen is where someone used an opendir() to open a
directory and then they did close() on that handle, not closedir(). Soon
the program ran out of directory handles.

Grep through your code for any occurence of 'open' or creating a new
Filehandle object of some kind. In long-running processes like your
daemon you should probably keep the scope of filehandle objects as tight
as possible, maybe localise normal file/directory handles, and ensure
that you close handles as soon as you possibly can.

The /proc filesystem mentioned by zentara is common but not available on
all systems - just something to watch out for. The handy thing about the
links in fd is that they point, on my system anyway, to the actual
filenames, so if I do 'ls -lab' in that directory I can see what files
are open.

P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top