How to sync a file on FreeBSD?

Polytropon freebsd at edvax.de
Fri Jul 22 11:21:11 UTC 2011


On Thu, 21 Jul 2011 23:44:00 -0700 (PDT), Unga wrote:
> How to sync a file on FreeBSD (esp. on 8.1) to disk?
> 
> I used fsync(2), but does not immediately flush to disk.
> 
> I want my writing to a file (a log file) immediately
> available to other users to read.

Maybe you can use system("/bin/sync"); or sync(); in
your program?

Check "man 8 sync": "force completion of pending disk
writes (flush cache)" as well as "man 2 sync": "The
sync() system call forces a write of dirty (modified)
buffers in the block buffer cache out to disk."

Is this "immediately" enough for your needs?


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list