[PLUG] Weird Output of a C program in Linux
pranavpeshwe at gmail.com
Tue Jul 17 04:12:00 PDT 2007
On 7/17/07, Pramod Sonar <pramod5393 at gmail.com> wrote:
> Hi Ashu
> you are right ! Hello world should be print only ones!
> but it's printing twice as when printf executes it does not send data to
> output buffer.
IMHO, it does send the data to the buffer. Due to the fork, the new
task(child) gets a copy of the buffer (which already contains the 'Hello
World!' string). This(fork()) is where the duplication occurs. Further
printfs in the two tasks lead to flushing of their respective buffers to the
console. With a '\n' after 'Hello World!', the child would get an empty
buffer to begin with.
More information about the plug-mail