I'd try the following:
#!/usr/bin/perl -w
use strict;
use File::Spec;
use POSIX qw(tmpnam);
use Win32API::File;
my $num = shift || 100000;
my (@tempfiles, @temphandles);
#impatience
$| = 1;
END {
map {CloseHandle $_ } @temphandles;
#hubris
map {unlink $_ } @tempfiles;
};
my $temp_dir = File::Spec->tmpdir();
while($num--)
{
#laziness
my $path = File::Spec->rel2abs(File::Spec->catfile($temp_dir,
tmpnam() ));
my $hObject= Win32API::File::createFile( $path, 'qrwtc' );
push @temphandles, $hObject;
push @tempfiles, $path;
print "object: $hObject :", $^E, "\n";
}
sleep(60);
I was able to open 100,000 filehandles with no problem, though that
unlink kinda acts weird. DeleteFile might work, but I figured this was
enough to start you in the right direction.
cabz wrote:
Hello!
I am new perl (again).
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
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs