Path: utzoo!attcan!uunet!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.unix.questions Subject: _cleanup() before fork()? (was Re: How to terminate a child ...) Message-ID: <775@mwtech.UUCP> Date: 1 Jun 90 22:57:43 GMT References: <24504.26542926@kuhub.cc.ukans.edu> <12932@smoke.BRL.MIL> <790:May2221:05:4490@stealth.acf.nyu.edu> <12960@smoke.BRL.MIL> <845: Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 30 In article <845:May2718:47:2590@stealth.acf.nyu.edu> brnstnd@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@mwtech.UUCP, voice: 49-(0)6151-6 56 83