redhat-list@redhat.com
[Top] [All Lists]

Re: bug in glibc? (was: redhat-list Digest, Vol 47, Issue 16)

Subject: Re: bug in glibc? was: redhat-list Digest, Vol 47, Issue 16
From: Imed Chihi
Date: Fri, 18 Jan 2008 17:50:37 +0000
On Fri, 2008-01-18 at 12:00 -0500, redhat-list-request@xxxxxxxxxx wrote:
> Message: 8
> Date: Fri, 18 Jan 2008 17:56:13 +0530
> From: krishnaakishore@xxxxxxxxx
> Subject: bug in glibc?
> To: "General Red Hat Linux discussion list" <redhat-list@xxxxxxxxxx>
> Message-ID:
>       <eab29e90801180426l2a0e2a05vff9664e78c56e42b@xxxxxxxxxxxxxx>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hi all,
> 
> I have a query regarding the output of the following code:
> 
> #include<stdio.h>
> #include<stdlib.h>
> #include<unistd.h>
> main(){
>       int a=0;
>       while(1){
>               printf("XXX(%d)",++a);
>               sleep(1);
>               if(fork()==0){printf("\n");exit(0);}
>               //you can remove the printf here,
>               //its just to enhance the readability of output
> 
>       }
> }
> 
> The output should actually be:
> XXX(1)
> XXX(2)
> XXX(3)
> XXX(4)
> XXX(5)
> XXX(6) (and so on)
> 
> But the output actually is:
> XXX(1)
> XXX(1)XXX(2)
> XXX(1)XXX(2)XXX(3)
> XXX(1)XXX(2)XXX(3)XXX(4)
> XXX(1)XXX(2)XXX(3)XXX(4)XXX(5)
> XXX(1)XXX(2)XXX(3)XXX(4)XXX(5)XXX(6) (and so on)
> 
> The fork() call is triggering the flushing the buffers but not
> clearing them. Hence the data in the buffers is getting accumulated.

The flushing of buffers is triggered by the printf("\n"), not by fork().
glibc and the kernel are behaving as expected.

 -Imed

-- 
Imed Chihi - ØÙØØ ØÙØÙØÙ
Senior Technical Account Manager         Office: +44-1-252-362-962
http://www.redhat.com/promo/vendor     Mobile: +44-7-921-700-936

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

<Prev in Thread] Current Thread [Next in Thread>
  • Re: bug in glibc? (was: redhat-list Digest, Vol 47, Issue 16), Imed Chihi <=