in reply to how to close all files
First, get a list of file descriptors. On many Unix systems, you can use lsof for that, or look in the /proc filesystem (which will have a different format on different OSses). On my system, I can do:
Now you have a list of filedescriptors. Unfortunally, you cannot use Perl's close with just the filedescriptor. But don't despair, Perl does give you access to the system calls. syscall is unknown to many people, but it's powerful. On a Unix system, the following ought to work:my @fds = `ls /proc/$$/fd`; chomp @fds;
Frankly, I rather keep track of my filehandles. ;-)require 'syscall.ph'; # May have to run h2ph first. for my $fd (@fds) { syscall(&SYS_close, $fd) == -1 or die $!; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to close all files
by massa (Hermit) on Oct 23, 2008 at 13:46 UTC | |
by JavaFan (Canon) on Oct 23, 2008 at 14:22 UTC | |
by Illuminatus (Curate) on Oct 23, 2008 at 15:28 UTC | |
|
Re^2: how to close all files
by mr_mischief (Monsignor) on Oct 23, 2008 at 23:47 UTC |