UK based. Perl, XML/HTTP, SAP, Debian hacker.
I'm having a torrid time with File::Temp. I like the module and it works mostly well, but I'm not doing something correctly with it.
In an Apache/mod_Perl PerlRun applicatiion I have the following happening many times:
{ # start scope
($SFH, $softer) = tempfile(SUFFIX => ".data",
DIR => "/tmp/",
UNLINK => 1);
... stuff ...
unlink0 ($SFH, $softer);
} # end scope
This appears to works on Windows (Perl 5.6.1, Apache 1.3.26, File::Temp 0.12), without a problem, I don't run out of file handles, and I don't have files left over, but Windows isn't used as much. On the Linux box, same spec, much higher load levels, I've had miserable problems.
As far as I can tell it's simply confused because it's running under mod_Perl, and the Perl processor never ends, so the normal end of Perl clean up isn't happening. The way I would expect.
Trying to find out how many file handles a Linux system can or cannot have hasn't been easy either. I've done quite a bit of Goolging, but there the same thing out there many times, but so far I've not discovered any deep magic.
For example on two nearly identical RedHat 7.x systems cat gives:
It took me a long time to figure out that the middle number is the number of free, not the number of used file handles, and hence a small number is bad.
It's worse than that (Score:1)
From /usr/src/linux/Documentation/sysctl/fs.txt:
tempfile (Score:2, Informative)
What happens if you put a close $fh in there before you leave the routine?
-Dom
Re:tempfile (Score:2)
Dom2,
Useful comments. I agree it's a great module, the problem started when I was working with it on NT and Linux. When I'd finished NT was working okay, but Linux was not....
If you have an explicit
close $fh, then what I found was that the file was NOT deleted, and I can't remember if the file handle was. I've even tried an explicitunlinktoo.Like I said I feel part of the problem is that it's running under mod_perl PerlRun, which is a bit of an odd place!
Since I posted, I'm now at: 8192, 2781, 16
-- "It's not magic, it's work..."
Re:tempfile (Score:1)
The docs state that a file is not auto deleted, if a filehandle is requested as well as a filename. You have to unlink it yourself.
One more thing; You might wish to check whether or not the unlink fails: unlink( $fname ) or warn "unlink($fname): $!\n"
Oh, and to see whether filehandles are leaking in real, useful terms, the best thing to do is r
Re:tempfile (Score:2)
Dom,
I think I know what is going on! I created the following little script, popped it into my PerlRun folder on my home Linux box and tested all the permutations.
-- "It's not magic, it's work..."