----- Original Message -----
From: "Gerald Timothy quimpo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, December 22, 2001 3:09 PM
Subject: [plug] select(...) on disk files
hello all,
i've got some log file monitoring programs which currently use
popen ("tail -f <filename>","r"). for several reasons i'd like to
switch to using select(...). this is not working for me though. i've
used select(...) successfully elsewhere, in socket code, and i
don't see why it's not working here. is there something special
about disk files and select that i'm missing?
i've looked at the tail source code and while i've considered that
approach, i'd prefer to use select(...) or poll(....) {not tried poll yet}
to the read and sleep loop that tail uses.
thanks for any pointers.
hi gerald,
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.
_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]
To subscribe to the Linux Newbies' List: send "subscribe" in the body to
[EMAIL PROTECTED]