Reading in real time from a file without pipes

Oliver Fromme olli at
Fri Jan 5 08:56:05 UTC 2007

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

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 Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD:
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

More information about the freebsd-hackers mailing list