OK, I thought perhaps using the FileHandle module would help, I rewrote the script in the fashion below. And it remains limited to 3197 using the Cygwin shell or 2045 using cmd.exe. I _assume_ the issue is something to do with perl being an interpreted language and an environment variable?? Is there a method to get this script to open say 250,000 file handles (or whatever is the theoretical limit of file handles in Win32). As one can guess, I am limited in my programming experience, thus I don't know if I am barking up the wrong tree. Perhaps a compiled language should be used for this task????

Help, please...


#!/usr/bin/perl -w
use strict;

use FileHandle;
if([EMAIL PROTECTED]) {
       print "usage: filehandles <integer> <extension>\n";
       print "usage: <extension> is the file extension to \n";
       print "usage:             use when creating files. \n";
       print "example: filehandles 3197 tmp1";
       exit;
}
my $numFh = $ARGV[0];
my $fhExt = $ARGV[1] || '_tmp';
chomp($numFh);
if ($numFh =~ m/[^0-9]/) {
    print "Impossible! Usage: filehandles <integer>\n";
    print "\"$numFh\" is not an integer!! exiting...\n";
    exit;
}
$numFh++; # we have to add one because of the way I wrote the loop
my $fhLoop = 1; #start at one for readability
my @fileDb;
while ($fhLoop < $numFh) {
#    print "Opening filehandle $fhLoop\n"; #do we really need to print it all?
    $fileDb[$fhLoop] = new FileHandle "$fhLoop.$fhExt", "w" or die "\n\nError: 
$!";
    $fhLoop++;
}
$fhLoop--; # back it up one, cause the extra wasn't really created.
print "Created $fhLoop filehandle(s) hit any key to quit.\n";
my $waitforkeystroke = <STDIN>;
while ($fhLoop > 0) {
    close($fileDb[$fhLoop]) && unlink("$fhLoop.$fhExt")
        or die "\n\nError removing: $!\n";
    $fhLoop--;
}


cabz wrote:
Hello!

I am new (to) perl.

I am performing QA on software developed at my company. My task is to try to exhaust all file handles on the Win32 platform (Win2K and WinXP) and see how our software behaves. With the code below, I am able to open no more than 2045 file handles under a cmd.exe shell and 3197 under a Cygwin shell.

Regards,
Carlos

#!/usr/bin/perl -w

if([EMAIL PROTECTED]) {
       print "usage: filehandles <integer> \n";
       exit;
}
$totalfhs = shift; #I could use $ARGV[0];
$i = 1;
while ($i == $totalfhs || $i < $totalfhs) {
       open $ar[$i], ">_$i.tmp" or die "Could not open $i";
       $i++;
}
print $i-1 ." filehandles are open, hit any key to close \n";
$_ = <STDIN>;
$i--; #cheesy but it is what is needed here
while ($i > 0) {
       close($ar[$i]) or die "\n\nError closing: $!";
       unlink("_$i.tmp") or die "\n\nError deleting: $!";
       $i--;
}


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to