How to flush output to disk?

David Elliott dce at smsc.sony.com
Thu Dec 7 08:14:40 AEST 1989


In article <1025 at friar-taac.UUCP> matthew at friar-taac.UUCP (Matthew Stier - Sun Visualization Products) writes:
>In article <606 at caldwr.UUCP> rfinch at caldwr.UUCP (Ralph Finch) writes:
>>
>>Is there any way to force the output to be flushed more often, say every 15-30 minutes?
>
>The following, untested, script should do it. (I know using 'sync' is a little heavy 
>handed, but it gets the job done.)

Are we talking about the same thing?

Maybe SunOS changed this, but on most BSD systems, the disk buffers are
written every 30 seconds via the /etc/update command.  Even if they
weren't, when you open a file that someone has written to, you get
pages from the buffer cache first, so you should get the data.

The problem here is (probably) that Ralph's program is using stdio to
log its output, and since the data is going to a file, it gets buffered
inside the program.  In other words, the data hasn't even gotten
written yet.

The easiest way to fix this is to modify the program to either call
fflush() at certain intervals to force the buffers to be written, or
call setlinebuf() (or the equivalent) to force line-buffered output.
-- 
David Elliott
dce at smsc.sony.com | ...!{uunet,mips}!sonyusa!dce
(408)944-4073
"It's bigger than a breadbox, and smaller than the planet Jupiter."



More information about the Comp.unix.questions mailing list