Reading in real time from a file without pipes

Dan Nelson dnelson at allantgroup.com
Mon Dec 11 09:23:56 PST 2006


In the last episode (Dec 11), c0re dumped said:
> 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 ?

Take a look at how the tail command does it.  You can either stat the
file periodically then read the new data if you see the timestamp or
size change (portable), or use a kqueue to get notified immediately of
any updates (not portable).

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-hackers mailing list