develooper Front page | perl.perl5.porters | Postings from November 2000

Re: PerlIO - what next ?

Thread Previous | Thread Next
November 9, 2000 05:22
Re: PerlIO - what next ?
Message ID:
On Thu, Nov 09, 2000 at 12:51:03PM +0000, Nick Ing-Simmons wrote:
> Barries <> writes:
> >Now if only I could close all filehandles, I could make subprocesses a little
> >more isolated from the parent and more reliably daemonizable :).
> When built with -Duseperlio it would be trivial to have a "close all"
> there already has to be one as an "atexit" routine to flush the 
> buffers. To build on the way PerlIO_flush(NULL) does flush all 
> PerlIO_close(NULL) could so the same - but what should it look like to perl
> code (or should we just make perl do the right thing?)

Could you allow Perl-level access to a list of open filehandles that the
program could iterate over?  Thinking of how I'd use this in IPC::Run,
I'd like to be able to do something like this (psuedo-code follows):

   ## In parent, before forking any children:
   for my $fh ( IO::Handle->all_open_handles ) {
      if ( $fh->is_open_for_output ) {
         $fh->flush ;

   fork() ;

   ## In child, post-fork, pre-exec:
   for my $fh ( IO::Handle->all_open_handles ) {
      unless ( should_leave_open $fh ) {
         $fh->close ;

This is more general than providing fflush(0)-like behavior that might
be exposed by a IO::Handle->flushall() or ->closeall().  I don't see a
need for flushall() or closeall() to be do-able without referring to a
some module.

I'd like to see the list of filehandles and the filehandles themselves be
more inspectable.  For the latter, this would include what's layered
between them and the underlying OS handle.  But that's all less important
that Just Getting It Working.  And thanks for the work you're doing for

As another item, do the things that you are keeping in mind for the
Windows port include anything that might enable select-on-filehandles
when running under Windows like cygwin does?

- Barrie

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About