简体   繁体   中英

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

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 .

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM