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

Discussion in 'Perl Misc' started by Rex Gustavus Adolphus, Mar 4, 2004.

  1. 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
     
    Rex Gustavus Adolphus, Mar 4, 2004
    #1
    1. Advertising

  2. Rex Gustavus Adolphus

    pkent Guest

    In article <>,
    (Rex Gustavus Adolphus) wrote:

    > 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

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
     
    pkent, Mar 6, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. puzzlecracker
    Replies:
    8
    Views:
    1,284
    Chris Uppal
    Sep 7, 2006
  2. Replies:
    0
    Views:
    293
  3. Replies:
    1
    Views:
    248
    Dennis Lee Bieber
    Nov 25, 2006
  4. JG
    Replies:
    5
    Views:
    432
    Lawrence Kirby
    Feb 8, 2005
  5. Ara.T.Howard

    closing all open file descriptors

    Ara.T.Howard, Sep 14, 2004, in forum: Ruby
    Replies:
    3
    Views:
    283
    Kent Sibilev
    Sep 15, 2004
Loading...

Share This Page