EnderUNIX Team.


EnderUNIX tips

Mail to My Friend , Home Page

[ C/C++ ]

"depths of tail command code" - ATILIM BOY - (2004-08-26 22:26:56)   [5108]

there are two kinds of notifications mechanism on unix for
filedescriptor. these two are:

1. state-based - in which the kernel informs the application of the
current state of a file descriptor (eg. data available for reading)
2. event-based - in which the kernel informs the application of the
occurrence of a meaningful event for a file descriptor (eg. new data
appended, file attribute changed)

select() and poll() belongs to state-based notification. files such as
disk files (eg. /var/log/messages) are *always* ready for I/O, therefore,
its state is always ready... even EOF or empty file (filesize is zero) of a
given file returns its state as ready. whether you use select() or poll(),
its still the same... there is nothing wrong with your code... what you are
looking for is an event-based notification in order to catch that
filedescriptor when modified.. unfortunately, as far as i know, linux dont
have that kind of notification for a given filedescriptor but freebsd and
other variants of BSD have which is called kqueue(). kqueue() is the same
function as select() or poll() but extends its function, offers flexibility
and scalability but not portability as of the moment... that is why linux
tail program is using read() and sleep() which is inefficient while freebsd
is using kqueue().

fooler.
plug@lists.q-linux.com
Sun, 23 Dec 2001 21:59:18 +0800
From http://lists.q-linux.com/

Mail to My Friend , Home Page