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: 10c665,d4695b171a94685b X-Google-Attributes: gid10c665,public X-Google-Thread: 11035d,d4695b171a94685b X-Google-Attributes: gid11035d,public X-Google-Thread: fee84,d4695b171a94685b X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-06-01 00:26:41 PST Path: bga.com!news.sprintlink.net!demon!bt!pipex!howland.reston.ans.net!agate!overload.lbl.gov!eubie.lbl.gov!jin From: jin@eubie.lbl.gov (Guojun Jin[ITG]) 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: 31 May 1994 19:34:59 GMT Organization: Lawrence Berkeley Laboratory Distribution: inet Message-ID: <2sg3h3$onq@overload.lbl.gov> References: <2s0io0$248@overload.lbl.gov> <1994May26.180828.3893@arl.army.mil> NNTP-Posting-Host: eubie.lbl.gov Xref: bga.com comp.unix.osf.osf1:1822 comp.unix.solaris:8337 comp.unix.sys5.r4:1925 comp.bugs.sys5:51 In article <1994May26.180828.3893@arl.army.mil>, Doug Gwyn (ACISD/MCSB) wrote: >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.) Actually, this is not true. First of all, the BSD system has no such problem. Secondly, the gets() system call does not have such problem either (see original testing program). The fork() should duplicate the parent space to its child without any changes. Then, the child(ren) can inherit all resources to continue the execution. Of course, a patch can be applied to kludge fixing this problem (fflush) at not cost too much in this case (may not be true in the larger data set case); but it is still a bug. In this testing program, doing fflush() on input is not meanful, except re-postioning the file point postion (does this mean that system keep two positions for one file ??? Very poor implementation). If the input is a huge data set (say 100MB image data), then, does fflush() intend to flush entire data set into the system cache to get the file postion adjusted ? BSD does it better, and SGI fixed its problem, Why not others? -- /-------------- Jin Guojun ------------ v ---- Internet: g_jin@lbl.gov ----\ | Imaging & Distributed Computing | Usenet: ucbvax!g_jin@lbl.gov | | Lawrence Berkeley Laboratory | Bitnet: -- | | 50B-2239, Berkeley, CA 94720 - jin%george.lbl.gov@Csa3.LBL.Gov |