in reply to How to debug "Too Many Open Files" Error

The unix command lsof can be used to determine the opened files, maybe that helps you.

Maybe you could also check your code for pieces like this:

open HANDLE, $filename;

Where a glob (HANDLE) is used as a file handle, instead of a lexical variable:

open my $handle, $filename;

With the latter the files are automatically closed when $handle goes out of scope, so a forgotten close does much less harm.

Replies are listed 'Best First'.
Re^2: How to debug "Too Many Open Files" Error
by BrowserUk (Patriarch) on Sep 16, 2008 at 22:29 UTC
    Maybe you could also check your code for pieces like this: open HANDLE, $filename;

    On my system, if you re-use a glob handle, the old one gets closed. It would take thousands of hard-coded lines like that to be causing this problem.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Or maybe generated code in string evals. (Not very likely, but still possible)
Re^2: How to debug "Too Many Open Files" Error
by tonyb48 (Novice) on Sep 16, 2008 at 22:53 UTC
    Thanks so much for your quick response. This is good practice so I appreciate the recommendation. In this application I have had no cause to open any files directly, although I believe Authen::Captcha probably opens some and I use this to generate a session key when a user signs in. Some of the other modules I use may open files as well. Here is the only case I use an OPEN command:
    open ( MAIL, "|$sendmail -oi -t" ) or die "Cannot open $sendmail: $!";
    But this mail module has not been involved with any of the errors that have emerged. Is there a way to run lsof from inside my PERL script? If not, I can suggest it to my hosting service. Thanks, Tony
      You can run external commands from perl (not PERL please, it's not an abbreviation) with either system or qx (the latter might be more useful in your case).

      It is very unlikely that this line is causing the issue because normally opening a pipe does not count towards open files.