In addition to the method you've tried here, the FAQ also provides documentation on closing a filehandle using the syscall directly.
# from perlfaq5
require ’sys/syscall.ph’;
$rc = syscall(&SYS_close, $fd + 0); # must force numeric
die "can’t sysclose $fd: $!" unless $rc == -1;
The method you tried didn't work for me either (which makes me wonder why it's in the FAQ), but this one did. Here is the test script I used:
#!/usr/bin/perl -w
require 'sys/syscall.ph';
$| = 1;
open(OUT, ">foo");
&CloseAllOpenFiles();
print "done with close.\n";
sleep 20;
# go look at process with lsof to see if fd still open
sub CloseAllOpenFiles {
for my $fd (0 .. 1024) {
my $rc = syscall(&SYS_close, $fd);
warn "Can't sysclose $fd: $!" unless $rc == -1;
}
}
We're not surrounded, we're in a target-rich environment! |
---|