[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: fork or printf problem



Hi
       This question is the one i posted some time ago.
One thing i still couldn't understand is that  how printf distinguish
between a terminal and a file.
for it everything it has to do is to write to a file pointer ( fp = 1 )
.  How then the buffering changes with the type of file pointed by file
pointer 1.

TIA

Regards
Sumit




Binand Raj S wrote:

> Sumit Rangawala forced the electrons to say:
> > running the output executable of the following program as
> > $a.out
> > and
> > $a.out > test
> > give different results
> > WHY??
>
> Buffering. Read man setbuf for the full story. In particular, stdout,
> when directed to a terminal, is line buffered, but when directed to a
> file is block buffered.
>
> Binand




> ****************************
> :#include <stdio.h>
> :#include <sys/types.h>
> :#include <unistd.h>
> :
> :main()
> :{
> :
> :    printf("Hello\n");
> :    if(fork()==0)
> :    {
> :        printf("world\n");
> :    }
> :}
> :
>
>
>



>
>
> ---------------------------------------------
> LIP is all for free speech.  But it was created
> for a purpose.  Violations of the rules of
> this list will result in stern action.