Unix standard output buffer problem

M.J.Shannon mjs at sfsup.UUCP
Tue Mar 4 04:07:06 AEST 1986


> 
>    I am looking for a little help in solving a rather interesting problem
> with SYSTEM V Unix.  Here are the symptoms:
> 
> 	I set the standard output flag byte to indicated no buffering:
> 		stdout -> _flag |= _IONBF;  /* Declared in stdio.h */
> 
> 	The code then does a fork() call.  At this point the child and
> 	parent process both report that the stdout -> _flag has the
> 	correct value (I.E. buffering is turned off).
> 
> 	The child process does an exec() type call.  The execed pgm
> 	reports that the stdout -> _flag has mysteriously been reinitialized
> 	to indicate buffering.
> 

First, you shouldn't mess with stdio's flags; to achieve the proper effect, use:
	setbuf(stdout, NULL);
Second, you need to understand what happens when your code executes an exec().
What happens is this: the current process image is abandoned (thrown away) and
a new process image is created (bearing NO relationship to what was there
before the exec() (well, not quite technically true; some kernel data
associated with the process is inherited)).  But, since stdio is not
implemented in the kernel, the new process does its own stdio initialization,
which includes setting up some buffering.
-- 
	Marty Shannon
UUCP:	ihnp4!attunix!mjs
Phone:	+1 (201) 522 6063

Disclaimer: I speak for no one.

"If I never loved, I never would have cried." -- Simon & Garfunkel



More information about the Comp.unix.wizards mailing list