From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 5 08:56:05 2007 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.ORG Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 68F3616A407 for ; Fri, 5 Jan 2007 08:56:05 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.freebsd.org (Postfix) with ESMTP id CFD2413C458 for ; Fri, 5 Jan 2007 08:56:04 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (zebixs@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id l058tvgn007600; Fri, 5 Jan 2007 09:56:03 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id l058tv4w007599; Fri, 5 Jan 2007 09:55:57 +0100 (CET) (envelope-from olli) Date: Fri, 5 Jan 2007 09:55:57 +0100 (CET) Message-Id: <200701050855.l058tv4w007599@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, fbsd@synoptic.org In-Reply-To: <20070104210958.GB46929@gort.synoptic.org> X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.2-20060425 ("Shillay") (UNIX) (FreeBSD/4.11-STABLE (i386)) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Fri, 05 Jan 2007 09:56:03 +0100 (CET) X-Mailman-Approved-At: Fri, 05 Jan 2007 12:32:24 +0000 Cc: Subject: Re: Reading in real time from a file without pipes X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, fbsd@synoptic.org List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jan 2007 08:56:05 -0000 Matthew Hudson wrote: > Mon Dec 11 09:08:37 PST 2006 c0re dumped wrote: > > I wonder if is possible to read data from a > > certain file without using a pipe. > > > > Let me explain: > > > > I have a process already writing messages to > > a logfile. I want to read all written data > > (without neither stop nor interfere normal > > log process) from another process in real > > time. > > > > How can I achieve it ? > > When on the command line, I do this using the program 'socat' > (net/socat in ports). I.e. > socat FILE:/var/log/messages,ignoreeof - How is that different from "tail -f +1"? > This gives me the same sort of behavior as 'tail -f' except that > it reads the entire file in first. That's what "+1" with tail(1) does. > I know this isn't what you were asking since but I wanted to take > the quick opportunity to brag about socat since I think it's the > most powerful and useful utility that nobody seems to have heard > about. Maybe that's because we already have tail(1) in the base system. ;-) > More in line to what you're asking, I think the magic you're looking > for is hinted to by the name of the option that socat uses, i.e. > 'ignoreeof'. I'd surmise that all that socat and 'tail -f' are > doing are reading until the end of a file and when they get a EOF, > they simply wait a few milliseconds and try again. No. FreeBSD's tail(1) does not "poll" at EOF, which would be quite ugly and inefficient. Instead it uses the kqueue interface, so the kernel notifies tail when more data is available. I've had a quick look at the socat sources; it doesn't seem to use the kqueue interface, so it probably polls at EOF. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. "Being really good at C++ is like being really good at using rocks to sharpen sticks." -- Thant Tessman