From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11035d,d4695b171a94685b,start X-Google-Attributes: gid11035d,public X-Google-Thread: f7cee,d4695b171a94685b,start X-Google-Attributes: gidf7cee,public X-Google-Thread: fee84,d4695b171a94685b,start X-Google-Attributes: gidfee84,public X-Google-Thread: 10c665,d4695b171a94685b,start X-Google-Attributes: gid10c665,public X-Google-ArrivalTime: 1994-05-26 11:08:28 PST Xref: gmd.de comp.unix.osf.osf1:3429 comp.unix.solaris:18723 comp.unix.sys5.r4:8330 comp.bugs.sys5:218 Newsgroups: comp.unix.osf.osf1,comp.unix.solaris,comp.unix.sys5.r4,comp.bugs.sys5 Path: gmd.de!nntp.gmd.de!xlink.net!scsing.switch.ch!swidir.switch.ch!univ-lyon1.fr!jussieu.fr!math.ohio-state.edu!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!zombie.ncsc.mil!admii!smokey!gwyn From: gwyn@arl.army.mil (Doug Gwyn (ACISD/MCSB) ) Subject: Re: Fork bug in Sys5 (or similar) system Message-ID: <1994May26.180828.3893@arl.army.mil> Organization: U.S. Army Research Laboratory APG, MD. References: <2s0io0$248@overload.lbl.gov> Distribution: inet Date: Thu, 26 May 1994 18:08:28 GMT In article <2s0io0$248@overload.lbl.gov> jin@eubie.lbl.gov (Guojun Jin[ITG]) writes: >In sys5 or similar system, the fork() will misplace a file position in a pointer >which opened by a parent and passed to children. The bugs affects only fread(). >fwrite() has not been tested yet, but similar peoblem should exist. No, that's not a bug! It's because you didn't realize that the standard I/O library does read-ahead buffering (block buffering). If you want to share a file position indicator it *must* be done with a mechanism that the operating system itself coordinates, e.g. the read() system call. The standard I/O library maintains a "virtual" file image, some of which (one bufferload) resides internally to the library (and thus the process to which the instance of the library is linked) and some of which is maintained externally by the operating system. This mechanism is also responsible for another kind of bug, where one process fwrite()s or fprintf()s or putc()s to a file, but the data does not seem to be there when another process tries to read it from that file. (The data is still in the writer's own buffer; it is flushed to the external file only under certain special circumstances, not upon every putc() etc.)