public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37785] New: printf + sleep = problems with output buffer
@ 2008-10-09 18:34 alexcastan at gmail dot com
2008-10-09 18:37 ` [Bug c/37785] printf without '\n' " paolo dot carlini at oracle dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: alexcastan at gmail dot com @ 2008-10-09 18:34 UTC (permalink / raw)
To: gcc-bugs
PLATFORM
PC i386 + GNU/Linux Ubuntu Hardy 8.04 + GCC 4.2.3
Compiling and Linking options: none.
Excuse my poor English. (By the way, what is "Host triplet", "Target triplet",
"Build triplet"?)
BUG:
"printf" really prints at terminal when finds '\n' character. So if I have a
simple "printf" iteration without '\n' like this ...
int n;
for (n=10; n>=0; n--) {
printf("%d ", n);
sleep(1);
};
... it doesn't works like expected. It just waits 10 seconds without printing
anything. After that prints whole line.
Another related problem with printf without '\n' and printf buffer using fork,
but I don't know if it is problem with printf or fork:
int n, pid;
for (n=10; n>=0; n--) {
printf("%d ", n);
sleep(1);
};
pid = fork();
if (pid == -1)
printf("Error\n");
else
if (pid == 0)
printf("I'm the child\n");
else
printf("I'm the parent\n");
it prints TWO times 10 9 8 7 6 5 4 3 2 1 0
It is not that executes two times, but if the fork send again the buffer to the
screen.
--
Summary: printf + sleep = problems with output buffer
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alexcastan at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37785
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/37785] printf without '\n' + sleep = problems with output buffer
2008-10-09 18:34 [Bug c/37785] New: printf + sleep = problems with output buffer alexcastan at gmail dot com
@ 2008-10-09 18:37 ` paolo dot carlini at oracle dot com
2008-10-09 18:47 ` pinskia at gcc dot gnu dot org
2008-10-09 20:25 ` alexcastan at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-10-09 18:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from paolo dot carlini at oracle dot com 2008-10-09 18:36 -------
In any case, sorry but this has nothing to do with the compiler.
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37785
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/37785] printf without '\n' + sleep = problems with output buffer
2008-10-09 18:34 [Bug c/37785] New: printf + sleep = problems with output buffer alexcastan at gmail dot com
2008-10-09 18:37 ` [Bug c/37785] printf without '\n' " paolo dot carlini at oracle dot com
@ 2008-10-09 18:47 ` pinskia at gcc dot gnu dot org
2008-10-09 20:25 ` alexcastan at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-10-09 18:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-10-09 18:46 -------
FILEs only fushes its internal buffer when it encounters a newline or when done
explicitly. Do it explicitly, use fflush (stdout);.
Anyways this is not a compiler or a library issue.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37785
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/37785] printf without '\n' + sleep = problems with output buffer
2008-10-09 18:34 [Bug c/37785] New: printf + sleep = problems with output buffer alexcastan at gmail dot com
2008-10-09 18:37 ` [Bug c/37785] printf without '\n' " paolo dot carlini at oracle dot com
2008-10-09 18:47 ` pinskia at gcc dot gnu dot org
@ 2008-10-09 20:25 ` alexcastan at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: alexcastan at gmail dot com @ 2008-10-09 20:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from alexcastan at gmail dot com 2008-10-09 20:24 -------
Then the second problem it is also the normal behavior. The fork()
makes child inherit the unprinted parent buffer, then two similar buffers get
print later.
10 9 8 7 6 5 4 3 2 1 0 I'm the child
10 9 8 7 6 5 4 3 2 1 0 I'm the parent
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37785
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-10-09 20:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-09 18:34 [Bug c/37785] New: printf + sleep = problems with output buffer alexcastan at gmail dot com
2008-10-09 18:37 ` [Bug c/37785] printf without '\n' " paolo dot carlini at oracle dot com
2008-10-09 18:47 ` pinskia at gcc dot gnu dot org
2008-10-09 20:25 ` alexcastan at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).