Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jul 2011 13:33:14 +0200
From:      "C. P. Ghost" <cpghost@cordula.ws>
To:        Unga <unga888@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: How to sync a file on FreeBSD?
Message-ID:  <CADGWnjU3puwc5k8ab33FK-6Z=oimxQJWHCJdgN-yQKpSJdWS-g@mail.gmail.com>
In-Reply-To: <1311317040.38368.YahooMailClassic@web160115.mail.bf1.yahoo.com>
References:  <1311317040.38368.YahooMailClassic@web160115.mail.bf1.yahoo.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Fri, Jul 22, 2011 at 8:44 AM, Unga <unga888@yahoo.com> wrote:
> Hi all
>
> 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.

It shouldn't matter: as soon as write(2) completes, the
system-wide file cache -- not the disk -- is updated, and
other users will transparently read(2) from that cache,
not from the disk.

What you probably want is to flush the userspace buffers
of your I/O library as soon as you write a line of output:
See fflush(3), set[v]buf(3)... You may also use a non-buffered
stream for writing logs.

fsync(2) has other uses. In particular, it is of NO use as
long as the logging application doesn't flush its I/O caches
itself.

> Best regards
> Unga

-cpghost.

-- 
Cordula's Web. http://www.cordula.ws/



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?CADGWnjU3puwc5k8ab33FK-6Z=oimxQJWHCJdgN-yQKpSJdWS-g>