From owner-freebsd-questions@FreeBSD.ORG Fri Jul 22 12:10:37 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id F1C411065670; Fri, 22 Jul 2011 12:10:37 +0000 (UTC) Date: Fri, 22 Jul 2011 12:10:37 +0000 From: Alexander Best To: "C. P. Ghost" Message-ID: <20110722121037.GA98992@freebsd.org> References: <1311317040.38368.YahooMailClassic@web160115.mail.bf1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Cc: Unga , freebsd-questions@freebsd.org Subject: Re: How to sync a file on FreeBSD? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2011 12:10:38 -0000 On Fri Jul 22 11, C. P. Ghost wrote: > On Fri, Jul 22, 2011 at 8:44 AM, Unga 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. if you *really* want to see data being written to disk immediately and don't care about performance, do the following: 1) disable the write cache of your hdd (see ada(4) and ata(4) man pages) 2) mount your partition(s) with '-o sync' cheers. alex > > 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/