Java Mailing List Archive

http://www.redhatconfig.com/

Home » Red Hat Linux Discussion »

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

Imed Chihi

2008-01-18


Author LoginPost Reply
On Fri, 2008-01-18 at 12:00 -0500, redhat-list-request@(protected):
> Message: 8
> Date: Fri, 18 Jan 2008 17:56:13 +0530
> From: krishnaakishore@(protected)
> Subject: bug in glibc?
> To: "General Red Hat Linux discussion list" <redhat-list@(protected)>
> Message-ID:
>  <eab29e90801180426l2a0e2a05vff9664e78c56e42b@(protected)>
> 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@(protected)
https://www.redhat.com/mailman/listinfo/redhat-list
©2008 redhatconfig.com - Jax Systems, LLC, U.S.A.