From owner-freebsd-questions@FreeBSD.ORG Fri Jul 22 11:33:15 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B9E31106564A for ; Fri, 22 Jul 2011 11:33:15 +0000 (UTC) (envelope-from cpghost@cordula.ws) Received: from mail-vx0-f182.google.com (mail-vx0-f182.google.com [209.85.220.182]) by mx1.freebsd.org (Postfix) with ESMTP id 7F2698FC13 for ; Fri, 22 Jul 2011 11:33:15 +0000 (UTC) Received: by vxg33 with SMTP id 33so2109383vxg.13 for ; Fri, 22 Jul 2011 04:33:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.180.105 with SMTP id dn9mr1469848vdc.5.1311334394874; Fri, 22 Jul 2011 04:33:14 -0700 (PDT) Received: by 10.220.100.73 with HTTP; Fri, 22 Jul 2011 04:33:14 -0700 (PDT) X-Originating-IP: [93.221.165.159] In-Reply-To: <1311317040.38368.YahooMailClassic@web160115.mail.bf1.yahoo.com> References: <1311317040.38368.YahooMailClassic@web160115.mail.bf1.yahoo.com> Date: Fri, 22 Jul 2011 13:33:14 +0200 Message-ID: From: "C. P. Ghost" To: Unga Content-Type: text/plain; charset=ISO-8859-1 Cc: 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 11:33:15 -0000 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. 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/