Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Nov 2001 17:05:44 -0800 (PST)
From:      Alejandro Forero Cuervo <bachue@bachue.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/31836: When killed Perl should flush output buffers
Message-ID:  <200111080105.fA815if28745@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         31836
>Category:       bin
>Synopsis:       When killed Perl should flush output buffers
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 07 17:10:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Alejandro Forero Cuervo
>Release:        4.4-RELEASE
>Organization:
Freaks Unidos
>Environment:
FreeBSD hbzones.conelprofe.com 4.4-RELEASE FreeBSD 4.4-RELEASE #0: Tue Sep 18 11:57:08 PDT 2001     murray@builder.FreeBSD.org:/usr/src/sys/compile/GENERIC  i386

>Description:
When the Perl interpreter is killed with SIGINT or SIGTERM (and probably many
other trappable signals), it doesn't flush its output buffers.

By default, when someone calls Perl's print function, it performs unbuffered
writes.  When a Perl script exits, Perl does the right thing: it flushes the
output buffers.  However, when the Perl interpreter is killed, it doesn't flush
them.

This is confusing to many users (I just helped one in the spanish users'
mailing list) and forces them to call the autoflush method from IO::Handle or
set $| to 1 (to disable buffering) when all they really want is just to have
their streams flushed.

This doesn't affect GNU/Linux (Debian using Perl 5.6.0).  However, I have
tested it in OpenBSD and (unsurprisingly) it is also affected.

The Perl interpreter should catch most (all?  Hmm, what happens with SIGSEGV or
SIGBUS?  Hmm) trapable signals and automagically flush output buffers when they
are about to cause program termination.

I'm not sure if this is the right place to report this problem.  If I'm doing
something wrong, please forgive me and let me know so, in my efforts to help
FreeBSD, I no longer do it in the future.

>How-To-Repeat:
The following Perl script should illustrate well what happens:

    for ($i = 0; $i ne 10; $i ++) {
      sleep(1);
      print "!";
    }

When the user runs it, it exits after 10 seconds and the Perl interpreter
flushes the output buffer so the user sees "!!!!!!!!!!".

However, if the user interrupts the script (by, for instance, pressing C-c),
Perl does not flush the output buffer and the user sees nothing.

>Fix:
This doesn't fix the problem but is what the users have to do to get around it:
add
    $|=1;
at the beginning or their scripts or use IO::Handle's autoflush method.

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200111080105.fA815if28745>