[comp.os.vms] How do you flush buffers?

miw@uqcspe.OZ (Mark Williams) (11/05/87)

G'day,
      I have a small problem with writing to files that perhaps someone can
help me with.
	I am in the process of writing a program in PASCAL to collect data
from the statistics port of our MICOM circuit switch. The collection part of
it is ok, and the records are going obediently out to a sequential, direct
access, fixed record size file.
	The problem is that the program has to run all the time, but we also
wish to be able to read the file it is writing and get up-to date data. At this
stage I am opening the file with sharing = readonly. This allows another 
process to access the file, but unfortunately, you can't read anything! I then
set up a little timer AST routine which wakes up every 5 minutes or so, 
closes the file, FINDS the last element written, and attempts to TRUNCATE
the file to get back to generation mode at EOF. The trouble is, PASCAL
doesn't let you TRUNCATE or EXTEND a file which can be shared! So I can either
read the file and get nothing, or flush the file out regularly and not be
able to read it at all because it is locked.
	What I want to be able to do is have the file checkpointed 
regularly like NETSERVER.LOGs or batch LOGS, so others can read it while
it is being generated. Can I do this in PASCAL with a sequential file, or
do I have to use an indexed file? Is it possible to do this in FORTRAN or
C? (I am no great hacker in those languages, but I suppose I could be forced
if it were the best way to get this @#$% job which SHOULD be simple done)

Hoping some VAX guru can help a sorcerer's apprentice,

Mark Williams
ARPA: ccwilliams%wombat.decnet.uq.oz@uunet.uu.net
ACSNET: ccwilliams@wombat.decnet.uq
PSI: PSI%050527372000090::ccwilliams


-- 
The views expressed above are not necessarily those of my employer. In a
couple of hours they may not even be my own.

Small boys throw stones in fun, but the frogs die in ernest. -- Mark Twain.

kvc@nrcvax.UUCP (Kevin Carosso) (11/14/87)

In article <1655@uqcspe.OZ> miw@uqcspe.cs.uq.oz (Mark Williams) writes:
>G'day,
>      I have a small problem with writing to files that perhaps someone can
>help me with.

Mark goes on to explain that he creates a shareable log file, but the data
is not getting flushed out to that file.

What you need to do is call the RMS routine $FLUSH to get your data out
of RMS's buffering mechanisms and into the actual file.  $FLUSH, documented
in the RMS manual, requires the address of the RAB (Record Access Block)
of the record stream to be flushed.  You can get the RAB of a Pascal file
variable by calling the Pascal RTL routine PAS$RAB.  PAS$RAB is documented
in the Pascal manual.  It's a simple call as well, taking a Pascal file
variable returning the address of the RAB.

I have actually done this, and it works very well.  If you require, I can
try to dig up my code, but it's no longer handy to get to.  You'll need
to choose how often you want to flush.  Since you probably don't write
to your log file with ferocious intensity, else you'd have filled up
you disks by now, you may as well do a flush after every write.  That's what
I did.

        /Kevin Carosso                     kvc@nrcvax.uucp
         Network Research Co.              kvc%nrcvax@trwind.trw.com
                                           kvc@engvax.scg.hac.com
                                           kvc@ymir.bitnet