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! |
---|
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|