Number of kevents registered in kqueue

Dan Nelson dnelson at allantgroup.com
Fri Dec 16 14:21:07 PST 2005


In the last episode (Dec 16), Sen C. Farley said:
> I may have missed it in the man page, but I am unable to find a way
> to determine how many kevents are currently registered within a
> kqueue.  If there is no method for a count, how about a way to find
> if a kqueue is empty or not.  Besides tracking what events are still
> within a kqueue, this would make for an easier way to write an event
> loop.  Currently, calling kevent() on an empty kqueue will still
> block.

I don't think there's a way currently.  What I did in my local tree is
modify kern_kevent so that if the magic number -1 is passed in as
nchanges, it will return the entire queued event list back to the
caller in *eventlist, and return the number of events as the
returncode.  Very useful for debugging kqueue-using programs where you
want to compare what you think you're waiting for, and what the kernel
thinks you're waiting for :)

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-hackers mailing list