Re: 12.2: fork() causing getline() to repeat stdin endlessly
Hi,
it helps to do
fflush((stdout);
after each printf(), or to run before the loop:
setvbuf(stdout, NULL, _IONBF, 0);
So it is obvious that the usual output buffering of printf() causes the
repetitions of text.
The loop does not do any extra cycles, as i could confirm by inserting
a stderr message after ++line_num:
fprintf(stderr, "line_num= %d\n", line_num);
While the buffered printf() repeats its lines, the stderr message shows
no repetitions but counts nicely up to the end.
(I assume gdb disables buffering and thus suppresses the stdout
repetitions.)
Have a nice day :)
Thomas
Reply to: