From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7cee,d4695b171a94685b X-Google-Attributes: gidf7cee,public X-Google-Thread: fee84,d4695b171a94685b X-Google-Attributes: gidfee84,public X-Google-Thread: 10c665,d4695b171a94685b X-Google-Attributes: gid10c665,public X-Google-Thread: 11035d,d4695b171a94685b X-Google-Attributes: gid11035d,public X-Google-ArrivalTime: 1994-05-27 10:15:39 PST Path: bga.com!news.sprintlink.net!hookup!swrinde!pipex!uknet!EU.net!sun4nl!fwi.uva.nl!casper From: casper@fwi.uva.nl (Casper H.S. Dik) Newsgroups: comp.unix.osf.osf1,comp.unix.solaris,comp.unix.sys5.r4,comp.bugs.sys5 Subject: Re: Fork bug in Sys5 (or similar) system Date: 27 May 1994 13:40:02 GMT Organization: FWI, University of Amsterdam Distribution: inet Message-ID: <2s4t7i$6vl@mail.fwi.uva.nl> References: <2s0io0$248@overload.lbl.gov> <2s1kg2$7or@mail.fwi.uva.nl> <1994May26.181612.1484@cs.nott.ac.uk> <2s4c5i$ndt@mail.fwi.uva.nl> NNTP-Posting-Host: adam.fwi.uva.nl Xref: bga.com comp.unix.osf.osf1:1750 comp.unix.solaris:8122 comp.unix.sys5.r4:1886 comp.bugs.sys5:46 ddj@gradient.gradient.com (Dave Johnson) writes: > >I don't remember where I learned not to do exit() in a child that >hasn't exec'ed (maybe the BSTJ Nov '78 Unix paper?). This sort of >lore should be clearly stated in the manual pages (under both fork AND >exit in this case). Word-of-Net is nice, but you'd think after all >these years it would be officially noted. > I think you can find this in the old BSD vfork() manual pages, and perhaps in the newer ones as well. It says something to the effect that you should call _exit() after vfork() and then goes on to note in brackets: Even with fork it is wrong to call exit since buffered data would then be flushed twice. This used to apply only to output buffers, as flushing input buffers was something people didn't do. The SVR4 stdio implementation does an lseek(fileno(buf), -unread characters in buf, SEEK_CUR). if it maintained a proper idea of the current file position, it could instead do: lseek(fileno(buf), offset where we're supposed to be , SEEK_SET). However, this would require an lseek on each input buffer prior to each read. Though lseek isn't world's most expensive system call, and its costs are dwarfed in comparison, it may still be something you want to avoid. I'm not 100% sure, but a simple fflush((FILE*) 0) is probably sufficient prior to fork(). Casper