Jack L.
Jack L.

Reputation: 151

Why can I only open 2045 files with Tie::File on Windows?

I have the following code that tries to tie arrays to files. Except, when I run this code, it only creates 2045 files. What is the issue here?

#!/usr/bin/perl
use Tie::File;

for (my $i = 0; $i < 10000; $i++) {
    @files{$i} = ();
    tie @{$files{$i}}, 'Tie::File', "files//tiefile$i";
}

Edit: I am on windows

Upvotes: 3

Views: 669

Answers (2)

vladr
vladr

Reputation: 66701

You are accumulating open file handles (see ulimit -n, setrlimit RLIMIT_NOFILE/RLIMIT_OFILE), and you ultimately hit a 2048 open file descriptors limit (2045 + stdin + stdout + stderr.)

Under Windows you will have to rewrite your application so that it has at most 2048 open file handles at any one time, since the 2048 limit is hard limit (cannot be modified) in MSVC's stdio.

Upvotes: 14

Chas. Owens
Chas. Owens

Reputation: 64919

On Linux machines go to /etc/security/limits.conf and add or modify these lines

* soft nofile 10003
* hard nofile 10003

This will increase the number of files each process can have open to 10003 (remember that you always start with three open: stdin, stdout, and stderr).

Based on you comments it sounds like you are using a Win32 machine. I can't find a way to increase the number of open files per process, but you might, and I stress might, be able to handle this through fork'ing (which is really threading on Win32).

Upvotes: 2

Related Questions