From: jin@eubie.lbl.gov (Guojun Jin[ITG])
Subject: Re: Fork bug in Sys5 (or similar) system
Date: 31 May 1994 19:34:59 GMT [thread overview]
Message-ID: <2sg3h3$onq@overload.lbl.gov> (raw)
In-Reply-To: 1994May26.180828.3893@arl.army.mil
In article <1994May26.180828.3893@arl.army.mil>,
Doug Gwyn (ACISD/MCSB) <gwyn> <gwyn> 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 |
next prev parent reply other threads:[~1994-05-31 19:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-05-25 22:16 Fork bug in Sys5 (or similar) system Guojun Jin[ITG]
1994-05-26 7:52 ` Casper H.S. Dik
1994-05-26 18:16 ` William Armitage
1994-05-27 8:48 ` Casper H.S. Dik
1994-05-27 12:59 ` Dave Johnson
1994-05-27 13:40 ` Casper H.S. Dik
1994-05-28 2:51 ` Doug Gwyn (ACISD/MCSB) <gwyn>
1994-05-31 1:25 ` Peter da Silva
1994-05-26 18:08 ` Doug Gwyn (ACISD/MCSB) <gwyn>
1994-05-31 19:34 ` Guojun Jin[ITG] [this message]
1994-05-31 20:07 ` Casper H.S. Dik
1994-06-01 22:06 ` Peter da Silva
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox