From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 23 15:02:55 2012 Received: (at submit) by debbugs.gnu.org; 23 Nov 2012 20:02:55 +0000 Received: from localhost ([127.0.0.1]:35248 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TbzSh-0001cQ-5c for submit@debbugs.gnu.org; Fri, 23 Nov 2012 15:02:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56719) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TbpI8-0007Hp-23 for submit@debbugs.gnu.org; Fri, 23 Nov 2012 04:11:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbpGh-0001PR-3e for submit@debbugs.gnu.org; Fri, 23 Nov 2012 04:09:54 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, WEIRD_QUOTING autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:39642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbpGh-0001PN-0Q for submit@debbugs.gnu.org; Fri, 23 Nov 2012 04:09:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:37186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbpGb-0002tu-9P for bug-coreutils@gnu.org; Fri, 23 Nov 2012 04:09:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbpGV-0001Mu-Ev for bug-coreutils@gnu.org; Fri, 23 Nov 2012 04:09:45 -0500 Received: from mail1.windriver.com ([147.11.146.13]:36865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbpGV-0001Mj-4g for bug-coreutils@gnu.org; Fri, 23 Nov 2012 04:09:39 -0500 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.14.5/8.14.3) with ESMTP id qAN99cdb024605 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Fri, 23 Nov 2012 01:09:38 -0800 (PST) Received: from [128.224.158.232] (128.224.158.232) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.2.318.4; Fri, 23 Nov 2012 01:09:36 -0800 Message-ID: <50AF3D4E.9040103@windriver.com> Date: Fri, 23 Nov 2012 17:09:34 +0800 From: liyu User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: Subject: A puzzling issue with "tee". Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [128.224.158.232] X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 23 Nov 2012 15:02:53 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.0 (-----) 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 #include int main(void) { printf("xxxxx\n"); sleep(3); printf("yyyyy\n"); sleep(3); printf("zzzzz\n"); return 0; } ================================== Regards, colin From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 23 17:51:44 2012 Received: (at 12975) by debbugs.gnu.org; 23 Nov 2012 22:51:44 +0000 Received: from localhost ([127.0.0.1]:35413 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tc263-0005Sk-Sf for submit@debbugs.gnu.org; Fri, 23 Nov 2012 17:51:44 -0500 Received: from joseki.proulx.com ([216.17.153.58]:56608) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tc261-0005SX-0y; Fri, 23 Nov 2012 17:51:42 -0500 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 9A2FB211D6; Fri, 23 Nov 2012 15:50:05 -0700 (MST) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 695C62DCC6; Fri, 23 Nov 2012 15:50:05 -0700 (MST) Date: Fri, 23 Nov 2012 15:50:05 -0700 From: Bob Proulx To: liyu Subject: Re: bug#12975: A puzzling issue with "tee". Message-ID: <20121123225004.GA7790@hysteria.proulx.com> References: <50AF3D4E.9040103@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50AF3D4E.9040103@windriver.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: 0.4 (/) X-Debbugs-Envelope-To: 12975 Cc: 12975@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: 0.4 (/) 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@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 From unknown Mon Jun 23 11:28:04 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 22 Dec 2012 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator