Rather than relying on the shell, if you have BSD::Resouce installed, you could:
#!/usr/bin/perl
use strict;
use warnings;
use BSD::Resource;
my $max = getrlimit( RLIMIT_NOFILE );
print "$max\n";
or if you're feeling really adventurous, with Inline::C
#!/usr/bin/perl
use Inline C;
use strict;
my $max = get_max_files();
print $max, "\n";
__END__
__C__
#include <sys/resource.h>
int get_max_files() {
struct rlimit rl;
if (getrlimit( RLIMIT_NOFILE, &rl) == 0) {
return rl.rlim_cur;
} else {
return -1;
}
}
(that needs more error checking).
|