GNU bug report logs - #11620
libc I/O buffers not flushed confusion

Previous Next

Package: coreutils;

Reported by: vikas bansal <vikasbansal27 <at> gmail.com>

Date: Sun, 3 Jun 2012 17:56:02 UTC

Severity: normal

Tags: notabug

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


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

From: Bob Proulx <bob <at> proulx.com>
To: vikas bansal <vikasbansal27 <at> gmail.com>
Cc: 11620 <at> debbugs.gnu.org
Subject: Re: bug#11620: Bug in sleep--linux 2.6
Date: Sun, 3 Jun 2012 14:37:41 -0600
retitle 11620 libc I/O buffers not flushed confusion
tag 11620 + notabug
close 11620
thanks

vikas bansal wrote:
> The sleep function when written at the end, forces the program to sleep,
> preventing him to execute any printf() instructions before it.

You have confused the sleep(3) libc C library routine with the
coreutils sleep(1) command line utility.

Please see this reference:

  http://www.gnu.org/software/coreutils/faq/#I-am-trying-to-compile-a-C-program-_002e_002e_002e

> Attaching a program.

Thank you for showing us the program even if it isn't anything to do
with coreutils.

> printf("going to sleep");

Missing "\n" newline at end of line?

> while (*shm != '*')
> sleep(1);
> exit(0);

The misunderstanding you are seeing is that printf() is calling the
libc stdio function which is buffering the output data.  This data is
only flushed when exit() is called.  The libc buffers data differently
depending upon the context of the file such as if the output is a tty
or a file.

If you wish to ensure that data is output then you should fflush() the
data in the libc I/O buffers.

  http://pubs.opengroup.org/onlinepubs/009696799/functions/fflush.html

Bob




This bug report was last modified 13 years and 41 days ago.

Previous Next


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