[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



On Fri, 2008-01-18 at 12:00 -0500, redhat-list-request redhat com wrote:
> Message: 8
> Date: Fri, 18 Jan 2008 17:56:13 +0530
> From: krishnaakishore gmail com
> Subject: bug in glibc?
> To: "General Red Hat Linux discussion list" <redhat-list redhat com>
> Message-ID:
> 	<eab29e90801180426l2a0e2a05vff9664e78c56e42b mail gmail com>
> 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]