#!/usr/bin/perl -w
use strict;
use Socket;
use BSD::Resource;
setrlimit(RLIMIT_NOFILE, 100000, 100000) or die "Cannot set rlimit - $!";
open OLDOUT, ">&STDOUT";
for my $max qw/1000 2000 4000 8000 16000/ {
open STDOUT, ">&", \*OLDOUT or die "reset STDOUT - $!";
my @fh;
my $count = 0;
while ($count < $max){
open my $fh, ">/tmp/temp.$count" or die "open $count - $!";
push @fh, $fh;
$count++;
}
print "opened $count files\n";
my ($in, $out);
my $buf;
open STDOUT, ">/dev/null" or die "redirect - $!";
socketpair( $in, $out, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die $!;
open STDOUT, ">&=", fileno($out) or die ">&= fileno(fd) - $!";
open STDOUT, ">&=", $out or die ">&= fd - $!";
open STDOUT, ">&", \*OLDOUT or die "reset2 STDOUT - $!";
print "no problem with $count!\n";
}
exit;
####
opened 1000 files
no problem with 1000!
opened 2000 files
no problem with 2000!
opened 4000 files
>&= fd - Illegal seek at lotsoffiles.pl line 23.
####
write(1, "opened 2000 files\n", 18opened 2000 files
dup2(2004, 1) = 1
fcntl(1, F_SETFD, 0) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff2b62da20) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(1, 0, SEEK_CUR) = 0
dup2(2005, 1) = 1
dup(2005) = 2006
dup2(2006, 2005) = 2005
fcntl(1, F_SETFD, 0) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff2b62da20) = -1 EINVAL (Invalid argument)
lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
dup2(2005, 1) = 1
fcntl(1, F_SETFD, 0) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff2b62da20) = -1 EINVAL (Invalid argument)
lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
dup(3) = 2006
dup2(2006, 1) = 1
fcntl(1, F_SETFD, 0) = 0
dup(3) = 4
write(1, "no problem with 2000!\n", 22no problem with 2000!
dup2(4, 1) = 1
fcntl(1, F_SETFD, 0) = 0
fstat(4004, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
write(1, "opened 4000 files\n", 18opened 4000 files
dup2(4004, 1) = 1
fcntl(1, F_SETFD, 0) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff2b62da20) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(1, 0, SEEK_CUR) = 0
dup2(4005, 1) = 1
dup(4005) = 4006
dup2(4006, 4005) = 4005
fcntl(1, F_SETFD, 0) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff2b62da20) = -1 EINVAL (Invalid argument)
lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
write(2, ">&= fileno(fd) - Illegal seek at"..., 57>&= fileno(fd) - Illegal seek at lotsoffiles.pl line 23.