GNU bug report logs - #12975
A puzzling issue with "tee".

Previous Next

Package: coreutils;

Reported by: liyu <yu.li <at> windriver.com>

Date: Fri, 23 Nov 2012 20:03:02 UTC

Severity: normal

Tags: notabug

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12975 in the body.
You can then email your comments to 12975 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#12975; Package coreutils. (Fri, 23 Nov 2012 20:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to liyu <yu.li <at> windriver.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 23 Nov 2012 20:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: liyu <yu.li <at> windriver.com>
To: <bug-coreutils <at> gnu.org>
Subject: A puzzling issue with "tee".
Date: Fri, 23 Nov 2012 17:09:34 +0800
Hello:

There is a issue puzzling me.
When I use the "tee" command, the log of a.out will lose if I use 
"ctrl+c" to kill it.

Steps:
======
(1). Complie source.
$ gcc test.c -Wall

(2). Run without "tee".
$ ./a.out
xxxxx
yyyyy
zzzzz
/*Tip: print between 'xxxxx and yyyyy' the program will sleep 3*/
appearance
----------
0 sec: print "xxxxx"
1 sec:
...
3 sec: print "yyyyy"
...
6 sec: print "zzzzz", program exit.

(3). Run with "tee".
$ ./a.out | tee ./test.log
xxxxx
yyyyy
zzzzz
appearance
----------
0 sec:
...
6 sec: print "xxxxx\n""yyyyy\n""zzzzz\n", program exit.

In step (3), before 6 sec input "ctrl + c", the log will lose.
I want to know how to let the log collect real-timely.


==================================
/*File name: test.c*/

#include <stdio.h>
#include <unistd.h>

int main(void)
{
        printf("xxxxx\n");

        sleep(3);
        printf("yyyyy\n");

        sleep(3);
        printf("zzzzz\n");


        return 0;
}
==================================


Regards,
colin




Information forwarded to bug-coreutils <at> gnu.org:
bug#12975; Package coreutils. (Fri, 23 Nov 2012 22:52:01 GMT) Full text and rfc822 format available.

Message #8 received at 12975 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: liyu <yu.li <at> windriver.com>
Cc: 12975 <at> debbugs.gnu.org
Subject: Re: bug#12975: A puzzling issue with "tee".
Date: Fri, 23 Nov 2012 15:50:05 -0700
tag 12975 + notabug
close 12975
thanks

liyu wrote:
> There is a issue puzzling me.

We welcome your discussion but in the future please post discussion
questions to coreutils <at> gnu.org and not to the bug tracker.  Thanks.

> When I use the "tee" command, the log of a.out will lose if I use
> "ctrl+c" to kill it.

Thank you for posting the details of your question with all of the
steps needed to reproduce the issue.  It helps a lot and most people
don't do as well with it.

> In step (3), before 6 sec input "ctrl + c", the log will lose.
> I want to know how to let the log collect real-timely.

You are running into libc stdio buffering.  Normally the libc stdio
called through printf(3) will collect up output and then output it all
at once, if the output device is not a terminal device.  This improves
performance for most applications.  But since you are piping the
output to tee the output is buffered and it is still in the memory of
your program.  When you interrupt it with SIGINT via control-C the
program exits and never writes the buffer to the output.  This doesn't
have anything to do with tee but is all within the component of your
program that is writing the output.

Rather than go into all of the details in this email let me point you
to a nice web page with much discussion about exactly this issue.
Please read through this.

  http://www.pixelbeat.org/programming/stdio_buffering/

Please let us know if this answers your questions.  Just group
follow-up reply-all to this message so as to keep the bug log in the
recipient list.

Bob




Added tag(s) notabug. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Fri, 23 Nov 2012 22:52:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 12975 <at> debbugs.gnu.org and liyu <yu.li <at> windriver.com> Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Fri, 23 Nov 2012 22:52:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 22 Dec 2012 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 186 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.