in reply to Re: how to close all files
in thread how to close all files

I think this could not flush the last-written buffer on files... Maybe
exec env => $^X, $0, '--secret-forked-flag', @ARGV
would work better, as perl closes all files on exec??
[]s, HTH, Massa (κς,πμ,πλ)

Replies are listed 'Best First'.
Re^3: how to close all files
by JavaFan (Canon) on Oct 23, 2008 at 14:22 UTC
    From perldoc -f fork:
    Beginning with v5.6.0, Perl will attempt to flush all files opened for output before forking the child process, but this may not be supported on some platforms (see perlport). To be safe, you may need to set $| ($AUTOFLUSH in English) or call the "autoflush()" method of "IO::Handle" on any open handles in order to avoid duplicate output.
    Forking cannot easily be replaced with an exec of itself. The process may have done extensive computation for instance. Furthermore, after an exec(), you still have open file handles: STDIN, STDOUT and STDERR.
Re^3: how to close all files
by Illuminatus (Curate) on Oct 23, 2008 at 15:28 UTC
    Why do you care about flushing the last write? Presumably the reason for the closes is to leave the control of all the open files to the parent.

    As for what JavaFan suggests, keeping track of open file descriptors when you know you might need to close them all at the same time is painful, but probably the wisest. Simply finding the open descriptors and closing them may or may not be a good idea. Some open descriptors may be within the context of included modules, and simply closing the descriptor without invoking the 'normal' close/disconnect/exit method might not produce the expected/desired results.