_cleanup() before fork()? (was Re: How to terminate a child ...)
Martin Weitzel
martin at mwtech.UUCP
Sat Jun 2 08:57:43 AEST 1990
In article <845:May2718:47:2590 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
[dd ...]
>Using fflush() before a fork() is never wrong in practice; it's the only
>way to guarantee that the child can safely use stdio; and the possible
>efficiency hit is miniscule compared to the fork() time. While there may
>be a few exceptions, novices should learn fflush()-fork() rather than a
>fork()-_exit() that will ``mysteriously'' lose output.
One remark to that: Requiring (or teaching novices) to fflush() all
output streams before a fork() tends to clutter up the source
with unnecessary global variables or introduce many additional
parameters: If the program is halfway structured chances are big
that the respective FILE-pointers are not normally visible at the
point were the program fork()s.
It would be quite helpful if stdio had officially defined some
"fflush_all()" operation - which is necessary anyway, because its
implicitly called by exit(). For as much as I know the usual name
of this routine is "_cleanup()", but using it - of course - is not
recommendable for portable programs.
BTW: I would not be surprised if someone finds it a useful idea
to make fork() call _cleanup() implicitly some day, because he was
burned by accidentially duplicated output. Though I would not like to
see this, there have allready been worse things in this area, eg.
fiddling with PATH and UID's within execv(), which has broken some clean
and useful code in the attempt to provide a general fix for sloppily
designed programs.
--
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83
More information about the Comp.unix.questions
mailing list