> >Tell me this isn't so. I am developing an app on Linux that relies
> >on disk files to pass data between differents processes. In debugging
> >this app I discovered that in many occasions the data written to the
> >file was not flushed to disk until the file was closed! This app relies
> >heavily on disk I/O and I posted a question recently on how to tune the
> >Linux disk cache for optimum performance (I received only one reply
> >that said that Linux uses all available free memory for disk cache).
> >Anyway is it true that I have to close and reopen the file after EACH
> >write to insure it is written to disk so this or another process can
> >read it? This seems like very strange behavior as even if the data is
> >in a memory resident cache, when a read occurs for that data it should
> >be retrieved from the cache or disk. Please help me understand this.
> First of all, in the GNU c library reference manual, I find
> int fflush(FILE *stream)
> which causes any buffered output on stream to be delivered to the
> file. It returns EOF if a write error occurse, 0 otherwise.
> 1) always read the manual
Unfortunatly I am not using buffered streams, I am using plain old
open(...) and write(...), and as far as I can tell there is no corresponding
flush(...) for nonbuffered I/O
Quote:> 2) If you are using disk files to exchange data between processes,
> there is no telling what else you are doing, and so it is hard to help
> you with your problems: You should have included the code you are
> using to write to the file.
The code is rather lengthy and I am requesting some general information
rather than a "bug" fix to my code. In particular if I write to a file,
do an lseek to somewhere, do a read, then lseek back to the first place
I wrote and try to read it, the data is not correct unless I close and
re-open the file. I could probably post a trivial example of this
but I wonder if this is known behavior (ie. having to close after a write
to flush it to disk) OR if I have a wierd problem.
Quote:> 3) Pipes or sockets are a better idea, if you want to transfer data
> between processes. Sockets are fascinating and they are What Is Done.
Thanks very much for the suggestion. As it turns out this is a network server
program and does use sockets to exchange data between clients (what a
concept!). However for this program I need to implement persistant queues
to have other processes on this machine process the data retreived by this
network server. My implementation must be portable to other Uni so I
can't use shared memory to implement the queues. I decided on disk files
as queues using flock to mediate access. "What Is Done" to implement
persistant queues?
Don Rubin Voice: 301-588-8010
Systems Engineering Technology Inc. Fax: 301-588-0154
Silver Spring, MD 20910-1121 http://www.setinc.com
finger for PGP public key