1ad35a4c9SJonathan Lemon.\" Copyright (c) 2000 Jonathan Lemon 2ad35a4c9SJonathan Lemon.\" All rights reserved. 3ad35a4c9SJonathan Lemon.\" 4ad35a4c9SJonathan Lemon.\" Redistribution and use in source and binary forms, with or without 5ad35a4c9SJonathan Lemon.\" modification, are permitted provided that the following conditions 6ad35a4c9SJonathan Lemon.\" are met: 7ad35a4c9SJonathan Lemon.\" 1. Redistributions of source code must retain the above copyright 8ad35a4c9SJonathan Lemon.\" notice, this list of conditions and the following disclaimer. 9ad35a4c9SJonathan Lemon.\" 2. Redistributions in binary form must reproduce the above copyright 10ad35a4c9SJonathan Lemon.\" notice, this list of conditions and the following disclaimer in the 11ad35a4c9SJonathan Lemon.\" documentation and/or other materials provided with the distribution. 12ad35a4c9SJonathan Lemon.\" 13ad35a4c9SJonathan Lemon.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND 14ad35a4c9SJonathan Lemon.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15ad35a4c9SJonathan Lemon.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16ad35a4c9SJonathan Lemon.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17ad35a4c9SJonathan Lemon.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18ad35a4c9SJonathan Lemon.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19ad35a4c9SJonathan Lemon.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20ad35a4c9SJonathan Lemon.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21ad35a4c9SJonathan Lemon.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22ad35a4c9SJonathan Lemon.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23ad35a4c9SJonathan Lemon.\" SUCH DAMAGE. 24ad35a4c9SJonathan Lemon.\" 25ad35a4c9SJonathan Lemon.\" $FreeBSD$ 26ad35a4c9SJonathan Lemon.\" 27ad35a4c9SJonathan Lemon.Dd April 14, 2000 28ad35a4c9SJonathan Lemon.Dt KQUEUE 2 29ad35a4c9SJonathan Lemon.Os 30ad35a4c9SJonathan Lemon.Sh NAME 314451bb5dSJonathan Lemon.Nm kqueue , 324451bb5dSJonathan Lemon.Nm kevent 33ad35a4c9SJonathan Lemon.Nd kernel event notification mechanism 344451bb5dSJonathan Lemon.Sh LIBRARY 354451bb5dSJonathan Lemon.Lb libc 36ad35a4c9SJonathan Lemon.Sh SYNOPSIS 37200f7053SBruce Evans.Fd #include <sys/types.h> 38ad35a4c9SJonathan Lemon.Fd #include <sys/event.h> 3934bdee5bSGuido van Rooij.Fd #include <sys/time.h> 40ad35a4c9SJonathan Lemon.Ft int 41ad35a4c9SJonathan Lemon.Fn kqueue "void" 42ad35a4c9SJonathan Lemon.Ft int 43a8e65b91SJonathan Lemon.Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout" 445d1c9c56SJonathan Lemon.Fn EV_SET "&kev" ident filter flags fflags data udata 45ad35a4c9SJonathan Lemon.Sh DESCRIPTION 46ad35a4c9SJonathan Lemon.Fn kqueue 47ad35a4c9SJonathan Lemonprovides a generic method of notifying the user when an event 48ad35a4c9SJonathan Lemonhappens or a condition holds, based on the results of small 49ad35a4c9SJonathan Lemonpieces of kernel code termed filters. 503c63f48cSSheldon HearnA kevent is identified by the (ident, filter) pair; there may only 51ad35a4c9SJonathan Lemonbe one unique kevent per kqueue. 524451bb5dSJonathan Lemon.Pp 53ad35a4c9SJonathan LemonThe filter is executed upon the initial registration of a kevent 543c63f48cSSheldon Hearnin order to detect whether a preexisting condition is present, and is also 55ad35a4c9SJonathan Lemonexecuted whenever an event is passed to the filter for evaluation. 56ad35a4c9SJonathan LemonIf the filter determines that the condition should be reported, 57ad35a4c9SJonathan Lemonthen the kevent is placed on the kqueue for the user to retrieve. 584451bb5dSJonathan Lemon.Pp 59ad35a4c9SJonathan LemonThe filter is also run when the user attempts to retrieve the kevent 603c63f48cSSheldon Hearnfrom the kqueue. 613c63f48cSSheldon HearnIf the filter indicates that the condition that triggered 62ad35a4c9SJonathan Lemonthe event no longer holds, the kevent is removed from the kqueue and 63ad35a4c9SJonathan Lemonis not returned. 644451bb5dSJonathan Lemon.Pp 65ad35a4c9SJonathan LemonMultiple events which trigger the filter do not result in multiple 66ad35a4c9SJonathan Lemonkevents being placed on the kqueue; instead, the filter will aggregate 67ad35a4c9SJonathan Lemonthe events into a single struct kevent. 68ad35a4c9SJonathan LemonCalling 69ad35a4c9SJonathan Lemon.Fn close 70ad35a4c9SJonathan Lemonon a file descriptor will remove any kevents that reference the descriptor. 71ad35a4c9SJonathan Lemon.Pp 72ad35a4c9SJonathan Lemon.Fn kqueue 73ad35a4c9SJonathan Lemoncreates a new kernel event queue and returns a descriptor. 74af7b56f4SJohn-Mark GurneyThe queue is not inherited by a child created with 75af7b56f4SJohn-Mark Gurney.Xr fork 2 . 763c63f48cSSheldon HearnHowever, if 773c63f48cSSheldon Hearn.Xr rfork 2 78ee85cf8bSJonathan Lemonis called without the 793c63f48cSSheldon Hearn.Dv RFFDG 80ee85cf8bSJonathan Lemonflag, then the descriptor table is shared, 81af7b56f4SJohn-Mark Gurneywhich will allow sharing of the kqueue between two processes. 82ad35a4c9SJonathan Lemon.Pp 83ad35a4c9SJonathan Lemon.Fn kevent 84ad35a4c9SJonathan Lemonis used to register events with the queue, and return any pending 85ad35a4c9SJonathan Lemonevents to the user. 86ad35a4c9SJonathan Lemon.Fa changelist 87a8e65b91SJonathan Lemonis a pointer to an array of 88ad35a4c9SJonathan Lemon.Va kevent 89ad35a4c9SJonathan Lemonstructures, as defined in 900e35d76eSDima Dorfman.Aq Pa sys/event.h . 91ad35a4c9SJonathan LemonAll changes contained in the 92ad35a4c9SJonathan Lemon.Fa changelist 93ad35a4c9SJonathan Lemonare applied before any pending events are read from the queue. 94ad35a4c9SJonathan Lemon.Fa nchanges 95ad35a4c9SJonathan Lemongives the size of 96ad35a4c9SJonathan Lemon.Fa changelist . 97ad35a4c9SJonathan Lemon.Fa eventlist 98ad35a4c9SJonathan Lemonis a pointer to an array of kevent structures. 99ad35a4c9SJonathan Lemon.Fa nevents 100ad35a4c9SJonathan Lemondetermines the size of 101ad35a4c9SJonathan Lemon.Fa eventlist . 102ad35a4c9SJonathan LemonIf 103ad35a4c9SJonathan Lemon.Fa timeout 104ad35a4c9SJonathan Lemonis a non-NULL pointer, it specifies a maximum interval to wait 10502e1f978SJeroen Ruigrok van der Wervenfor an event, which will be interpreted as a struct timespec. If 106ad35a4c9SJonathan Lemon.Fa timeout 107ad35a4c9SJonathan Lemonis a NULL pointer, 108ad35a4c9SJonathan Lemon.Fn kevent 109ad35a4c9SJonathan Lemonwaits indefinitely. To effect a poll, the 110ad35a4c9SJonathan Lemon.Fa timeout 111ad35a4c9SJonathan Lemonargument should be non-NULL, pointing to a zero-valued 112ad35a4c9SJonathan Lemon.Va timespec 113ee85cf8bSJonathan Lemonstructure. The same array may be used for the 114ee85cf8bSJonathan Lemon.Fa changelist 115ee85cf8bSJonathan Lemonand 116ee85cf8bSJonathan Lemon.Fa eventlist . 117ad35a4c9SJonathan Lemon.Pp 1185d1c9c56SJonathan Lemon.Fn EV_SET 1195d1c9c56SJonathan Lemonis a macro which is provided for ease of initializing a 1205d1c9c56SJonathan Lemonkevent structure. 1215d1c9c56SJonathan Lemon.Pp 122ad35a4c9SJonathan LemonThe 123ad35a4c9SJonathan Lemon.Va kevent 124ad35a4c9SJonathan Lemonstructure is defined as: 125ad35a4c9SJonathan Lemon.Bd -literal 126ad35a4c9SJonathan Lemonstruct kevent { 127ad35a4c9SJonathan Lemon uintptr_t ident; /* identifier for this event */ 128ad35a4c9SJonathan Lemon short filter; /* filter for event */ 129ad35a4c9SJonathan Lemon u_short flags; /* action flags for kqueue */ 130ad35a4c9SJonathan Lemon u_int fflags; /* filter flag value */ 131ad35a4c9SJonathan Lemon intptr_t data; /* filter data value */ 132ad35a4c9SJonathan Lemon void *udata; /* opaque user data identifier */ 133ad35a4c9SJonathan Lemon}; 134ad35a4c9SJonathan Lemon.Ed 135ad35a4c9SJonathan Lemon.Pp 136ad35a4c9SJonathan LemonThe fields of 137ad35a4c9SJonathan Lemon.Fa struct kevent 138ad35a4c9SJonathan Lemonare: 139ad35a4c9SJonathan Lemon.Bl -tag -width XXXfilter 140ad35a4c9SJonathan Lemon.It ident 141ad35a4c9SJonathan LemonValue used to identify this event. 142ad35a4c9SJonathan LemonThe exact interpretation is determined by the attached filter, 143ad35a4c9SJonathan Lemonbut often is a file descriptor. 144ad35a4c9SJonathan Lemon.It filter 145ad35a4c9SJonathan LemonIdentifies the kernel filter used to process this event. The pre-defined 146ad35a4c9SJonathan Lemonsystem filters are described below. 147ad35a4c9SJonathan Lemon.It flags 148ad35a4c9SJonathan LemonActions to perform on the event. 149ad35a4c9SJonathan Lemon.It fflags 150ad35a4c9SJonathan LemonFilter-specific flags. 151ad35a4c9SJonathan Lemon.It data 152ad35a4c9SJonathan LemonFilter-specific data value. 153ad35a4c9SJonathan Lemon.It udata 154ad35a4c9SJonathan LemonOpaque user-defined value passed through the kernel unchanged. 155ad35a4c9SJonathan Lemon.El 156ad35a4c9SJonathan Lemon.Pp 157ad35a4c9SJonathan LemonThe 158ad35a4c9SJonathan Lemon.Va flags 159ad35a4c9SJonathan Lemonfield can contain the following values: 160ad35a4c9SJonathan Lemon.Bl -tag -width XXXEV_ONESHOT 161ad35a4c9SJonathan Lemon.It EV_ADD 162ad35a4c9SJonathan LemonAdds the event to the kqueue. Re-adding an existing event 163ad35a4c9SJonathan Lemonwill modify the parameters of the original event, and not result 164ad35a4c9SJonathan Lemonin a duplicate entry. Adding an event automatically enables it, 165ad35a4c9SJonathan Lemonunless overridden by the EV_DISABLE flag. 166ad35a4c9SJonathan Lemon.It EV_ENABLE 167ad35a4c9SJonathan LemonPermit 168ad35a4c9SJonathan Lemon.Fn kevent 169ad35a4c9SJonathan Lemonto return the event if it is triggered. 170ad35a4c9SJonathan Lemon.It EV_DISABLE 171ad35a4c9SJonathan LemonDisable the event so 172ad35a4c9SJonathan Lemon.Fn kevent 173ad35a4c9SJonathan Lemonwill not return it. The filter itself is not disabled. 174ad35a4c9SJonathan Lemon.It EV_DELETE 175ad35a4c9SJonathan LemonRemoves the event from the kqueue. Events which are attached to 176ad35a4c9SJonathan Lemonfile descriptors are automatically deleted on the last close of 177ad35a4c9SJonathan Lemonthe descriptor. 178ad35a4c9SJonathan Lemon.It EV_ONESHOT 179ad35a4c9SJonathan LemonCauses the event to return only the first occurrence of the filter 180ad35a4c9SJonathan Lemonbeing triggered. After the user retrieves the event from the kqueue, 181ad35a4c9SJonathan Lemonit is deleted. 182ad35a4c9SJonathan Lemon.It EV_CLEAR 183ad35a4c9SJonathan LemonAfter the event is retrieved by the user, its state is reset. 184ad35a4c9SJonathan LemonThis is useful for filters which report state transitions 185ad35a4c9SJonathan Lemoninstead of the current state. Note that some filters may automatically 186ad35a4c9SJonathan Lemonset this flag internally. 187ad35a4c9SJonathan Lemon.It EV_EOF 188ad35a4c9SJonathan LemonFilters may set this flag to indicate filter-specific EOF condition. 189ad35a4c9SJonathan Lemon.It EV_ERROR 190ad35a4c9SJonathan LemonSee 191ad35a4c9SJonathan Lemon.Sx RETURN VALUES 192ad35a4c9SJonathan Lemonbelow. 193ad35a4c9SJonathan Lemon.El 194ad35a4c9SJonathan Lemon.Pp 195ad35a4c9SJonathan LemonThe predefined system filters are listed below. 196ad35a4c9SJonathan LemonArguments may be passed to and from the filter via the 197ad35a4c9SJonathan Lemon.Va fflags 198ad35a4c9SJonathan Lemonand 199ad35a4c9SJonathan Lemon.Va data 200ad35a4c9SJonathan Lemonfields in the kevent structure. 20142635956SRuslan Ermilov.Bl -tag -width EVFILT_SIGNAL 202ad35a4c9SJonathan Lemon.It EVFILT_READ 203ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever 204ad35a4c9SJonathan Lemonthere is data available to read. 205ad35a4c9SJonathan LemonThe behavior of the filter is slightly different depending 206ad35a4c9SJonathan Lemonon the descriptor type. 2075d1c9c56SJonathan Lemon.Pp 20842635956SRuslan Ermilov.Bl -tag -width 2n 209ad35a4c9SJonathan Lemon.It Sockets 210ad35a4c9SJonathan LemonSockets which have previously been passed to 211ad35a4c9SJonathan Lemon.Fn listen 212ad35a4c9SJonathan Lemonreturn when there is an incoming connection pending. 213ad35a4c9SJonathan Lemon.Va data 214ad35a4c9SJonathan Lemoncontains the size of the listen backlog. 215ad35a4c9SJonathan Lemon.Pp 216ad35a4c9SJonathan LemonOther socket descriptors return when there is data to be read, 2175d1c9c56SJonathan Lemonsubject to the 2185d1c9c56SJonathan Lemon.Dv SO_RCVLOWAT 2195d1c9c56SJonathan Lemonvalue of the socket buffer. 2205d1c9c56SJonathan LemonThis may be overridden with a per-filter low water mark at the 2215d1c9c56SJonathan Lemontime the filter is added by setting the 2225d1c9c56SJonathan LemonNOTE_LOWAT 2235d1c9c56SJonathan Lemonflag in 2245d1c9c56SJonathan Lemon.Va fflags , 2255d1c9c56SJonathan Lemonand specifying the new low water mark in 2265d1c9c56SJonathan Lemon.Va data . 2275d1c9c56SJonathan LemonOn return, 228ad35a4c9SJonathan Lemon.Va data 229ad35a4c9SJonathan Lemoncontains the number of bytes in the socket buffer. 230ad35a4c9SJonathan Lemon.Pp 231ad35a4c9SJonathan LemonIf the read direction of the socket has shutdown, then the filter 232ad35a4c9SJonathan Lemonalso sets EV_EOF in 2335d1c9c56SJonathan Lemon.Va flags , 2345d1c9c56SJonathan Lemonand returns the socket error (if any) in 2355d1c9c56SJonathan Lemon.Va fflags . 236ad35a4c9SJonathan LemonIt is possible for EOF to be returned (indicating the connection is gone) 237ad35a4c9SJonathan Lemonwhile there is still data pending in the socket buffer. 238ad35a4c9SJonathan Lemon.It Vnodes 239ad35a4c9SJonathan LemonReturns when the file pointer is not at the end of file. 240ad35a4c9SJonathan Lemon.Va data 241ad35a4c9SJonathan Lemoncontains the offset from current position to end of file, 242ad35a4c9SJonathan Lemonand may be negative. 24342635956SRuslan Ermilov.It "Fifos, Pipes" 244ad35a4c9SJonathan LemonReturns when the there is data to read; 245ad35a4c9SJonathan Lemon.Va data 246ad35a4c9SJonathan Lemoncontains the number of bytes available. 247ad35a4c9SJonathan Lemon.Pp 248ad35a4c9SJonathan LemonWhen the last writer disconnects, the filter will set EV_EOF in 249ad35a4c9SJonathan Lemon.Va flags . 250ad35a4c9SJonathan LemonThis may be cleared by passing in EV_CLEAR, at which point the 251ad35a4c9SJonathan Lemonfilter will resume waiting for data to become available before 252ad35a4c9SJonathan Lemonreturning. 253ad35a4c9SJonathan Lemon.El 254ad35a4c9SJonathan Lemon.It EVFILT_WRITE 255ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever 256ad35a4c9SJonathan Lemonit is possible to write to the descriptor. For sockets, pipes 257ad35a4c9SJonathan Lemonand fifos, 258ad35a4c9SJonathan Lemon.Va data 259ad35a4c9SJonathan Lemonwill contain the amount of space remaining in the write buffer. 260ad35a4c9SJonathan LemonThe filter will set EV_EOF when the reader disconnects, and for 261ad35a4c9SJonathan Lemonthe fifo case, this may be cleared by use of EV_CLEAR. 262ad35a4c9SJonathan LemonNote that this filter is not supported for vnodes. 2635d1c9c56SJonathan Lemon.Pp 2645d1c9c56SJonathan LemonFor sockets, the low water mark and socket error handling is 2655d1c9c56SJonathan Lemonidentical to the EVFILT_READ case. 266ad35a4c9SJonathan Lemon.It EVFILT_AIO 2675d1c9c56SJonathan LemonThe sigevent portion of the AIO request is filled in, with 2685d1c9c56SJonathan Lemon.Va sigev_notify_kqueue 2695d1c9c56SJonathan Lemoncontaining the descriptor of the kqueue that the event should 2705d1c9c56SJonathan Lemonbe attached to, 2715d1c9c56SJonathan Lemon.Va sigev_value 2725d1c9c56SJonathan Lemoncontaining the udata value, and 2735d1c9c56SJonathan Lemon.Va sigev_notify 2745d1c9c56SJonathan Lemonset to SIGEV_EVENT. 2755d1c9c56SJonathan LemonWhen the aio_* function is called, the event will be registered 2765d1c9c56SJonathan Lemonwith the specified kqueue, and the 277ad35a4c9SJonathan Lemon.Va ident 278ad35a4c9SJonathan Lemonargument set to the 279ad35a4c9SJonathan Lemon.Fa struct aiocb 280ad35a4c9SJonathan Lemonreturned by the aio_* function. 281ad35a4c9SJonathan LemonThe filter returns under the same conditions as aio_error. 282ad35a4c9SJonathan Lemon.Pp 2835d1c9c56SJonathan LemonAlternatively, a kevent structure may be initialized, with 2845d1c9c56SJonathan Lemon.Va ident 285a910f192SDima Dorfmancontaining the descriptor of the kqueue, and the 2865d1c9c56SJonathan Lemonaddress of the kevent structure placed in the 2875d1c9c56SJonathan Lemon.Va aio_lio_opcode 2885d1c9c56SJonathan Lemonfield of the AIO request. However, this approach will not work on 2895d1c9c56SJonathan Lemonarchitectures with 64-bit pointers, and should be considered depreciated. 290ad35a4c9SJonathan Lemon.It EVFILT_VNODE 291ad35a4c9SJonathan LemonTakes a file descriptor as the identifier and the events to watch for in 292ad35a4c9SJonathan Lemon.Va fflags , 293ad35a4c9SJonathan Lemonand returns when one or more of the requested events occurs on the descriptor. 294ad35a4c9SJonathan LemonThe events to monitor are: 295ad35a4c9SJonathan Lemon.Bl -tag -width XXNOTE_RENAME 296ad35a4c9SJonathan Lemon.It NOTE_DELETE 297ad35a4c9SJonathan Lemon.Fn unlink 298ad35a4c9SJonathan Lemonwas called on the file referenced by the descriptor. 299ad35a4c9SJonathan Lemon.It NOTE_WRITE 300ad35a4c9SJonathan LemonA write occurred on the file referenced by the descriptor. 301ad35a4c9SJonathan Lemon.It NOTE_EXTEND 302ad35a4c9SJonathan LemonThe file referenced by the descriptor was extended. 303ad35a4c9SJonathan Lemon.It NOTE_ATTRIB 304ad35a4c9SJonathan LemonThe file referenced by the descriptor had its attributes changed. 305ad35a4c9SJonathan Lemon.It NOTE_LINK 306ad35a4c9SJonathan LemonThe link count on the file changed. 307ad35a4c9SJonathan Lemon.It NOTE_RENAME 308ad35a4c9SJonathan LemonThe file referenced by the descriptor was renamed. 3095d1c9c56SJonathan Lemon.It NOTE_REVOKE 3105d1c9c56SJonathan LemonAccess to the file was revoked via 3115d1c9c56SJonathan Lemon.Xr revoke 2 3125d1c9c56SJonathan Lemonor the underlying fileystem was unmounted. 313ad35a4c9SJonathan Lemon.El 314ad35a4c9SJonathan Lemon.Pp 315ad35a4c9SJonathan LemonOn return, 316ad35a4c9SJonathan Lemon.Va fflags 317ad35a4c9SJonathan Lemoncontains the events which triggered the filter. 318ad35a4c9SJonathan Lemon.It EVFILT_PROC 319ad35a4c9SJonathan LemonTakes the process ID to monitor as the identifier and the events to watch for 320ad35a4c9SJonathan Lemonin 321ad35a4c9SJonathan Lemon.Va fflags , 322ad35a4c9SJonathan Lemonand returns when the process performs one or more of the requested events. 323ad35a4c9SJonathan LemonIf a process can normally see another process, it can attach an event to it. 324ad35a4c9SJonathan LemonThe events to monitor are: 325ad35a4c9SJonathan Lemon.Bl -tag -width XXNOTE_TRACKERR 326ad35a4c9SJonathan Lemon.It NOTE_EXIT 327ad35a4c9SJonathan LemonThe process has exited. 328ad35a4c9SJonathan Lemon.It NOTE_FORK 329ad35a4c9SJonathan LemonThe process has called 330ad35a4c9SJonathan Lemon.Fn fork . 331ad35a4c9SJonathan Lemon.It NOTE_EXEC 332ad35a4c9SJonathan LemonThe process has executed a new process via 333ad35a4c9SJonathan Lemon.Xr execve 2 334ad35a4c9SJonathan Lemonor similar call. 335ad35a4c9SJonathan Lemon.It NOTE_TRACK 336ad35a4c9SJonathan LemonFollow a process across 337ad35a4c9SJonathan Lemon.Fn fork 338ad35a4c9SJonathan Lemoncalls. The parent process will return with NOTE_TRACK set in the 339ad35a4c9SJonathan Lemon.Va fflags 340ad35a4c9SJonathan Lemonfield, while the child process will return with NOTE_CHILD set in 341ad35a4c9SJonathan Lemon.Va fflags 342ad35a4c9SJonathan Lemonand the parent PID in 343ad35a4c9SJonathan Lemon.Va data . 344ad35a4c9SJonathan Lemon.It NOTE_TRACKERR 345ad35a4c9SJonathan LemonThis flag is returned if the system was unable to attach an event to 346ad35a4c9SJonathan Lemonthe child process, usually due to resource limitations. 347ad35a4c9SJonathan Lemon.El 348ad35a4c9SJonathan Lemon.Pp 349ad35a4c9SJonathan LemonOn return, 350ad35a4c9SJonathan Lemon.Va fflags 351ad35a4c9SJonathan Lemoncontains the events which triggered the filter. 352ad35a4c9SJonathan Lemon.It EVFILT_SIGNAL 353ad35a4c9SJonathan LemonTakes the signal number to monitor as the identifier and returns 354ad35a4c9SJonathan Lemonwhen the given signal is delivered to the process. 355ad35a4c9SJonathan LemonThis coexists with the 356ad35a4c9SJonathan Lemon.Fn signal 357ad35a4c9SJonathan Lemonand 358ad35a4c9SJonathan Lemon.Fn sigaction 359ad35a4c9SJonathan Lemonfacilities, and has a lower precedence. The filter will record 360ad35a4c9SJonathan Lemonall attempts to deliver a signal to a process, even if the signal has 361ad35a4c9SJonathan Lemonbeen marked as SIG_IGN. Event notification happens after normal 362ad35a4c9SJonathan Lemonsignal delivery processing. 363ad35a4c9SJonathan Lemon.Va data 364ad35a4c9SJonathan Lemonreturns the number of times the signal has occurred since the last call to 365add06812SJonathan Lemon.Fn kevent . 366ad35a4c9SJonathan LemonThis filter automatically sets the EV_CLEAR flag internally. 367*e725a129SJonathan Lemon.It EVFILT_TIMER 368*e725a129SJonathan LemonEstablishes an arbitrary timer identified by 369*e725a129SJonathan Lemon.Va ident . 370*e725a129SJonathan LemonWhen adding a timer, 371*e725a129SJonathan Lemon.Va data 372*e725a129SJonathan Lemonspecifies the timeout period in milliseconds. 373*e725a129SJonathan LemonThe timer will be periodic unless EV_ONESHOT is specified. 374*e725a129SJonathan LemonOn return, 375*e725a129SJonathan Lemon.Va data 376*e725a129SJonathan Lemonconatains the number of times the timeout has expired since the last call to 377*e725a129SJonathan Lemon.Fn kevent . 378*e725a129SJonathan LemonThis filter automatically sets the EV_CLEAR flag internally. 379ad35a4c9SJonathan Lemon.El 380ad35a4c9SJonathan Lemon.Sh RETURN VALUES 381af7b56f4SJohn-Mark Gurney.Fn kqueue 382af7b56f4SJohn-Mark Gurneycreates a new kernel event queue and returns a file descriptor. 383af7b56f4SJohn-Mark GurneyIf there was an error creating the kernel event queue, a value of -1 is 384af7b56f4SJohn-Mark Gurneyreturned and errno set. 385af7b56f4SJohn-Mark Gurney.Pp 386ad35a4c9SJonathan Lemon.Fn kevent 387ad35a4c9SJonathan Lemonreturns the number of events placed in the 388bb33e422SChris Costello.Fa eventlist , 389ad35a4c9SJonathan Lemonup to the value given by 390bb33e422SChris Costello.Fa nevents . 391ad35a4c9SJonathan LemonIf an error occurs while processing an element of the 392bb33e422SChris Costello.Fa changelist 393ad35a4c9SJonathan Lemonand there is enough room in the 394bb33e422SChris Costello.Fa eventlist , 395ad35a4c9SJonathan Lemonthen the event will be placed in the 396bb33e422SChris Costello.Fa eventlist 397ad35a4c9SJonathan Lemonwith 398ad35a4c9SJonathan Lemon.Dv EV_ERROR 399ad35a4c9SJonathan Lemonset in 400ad35a4c9SJonathan Lemon.Va flags 401ad35a4c9SJonathan Lemonand the system error in 402ad35a4c9SJonathan Lemon.Va data . 403ad35a4c9SJonathan LemonOtherwise, 404ad35a4c9SJonathan Lemon.Dv -1 405ad35a4c9SJonathan Lemonwill be returned, and 406ad35a4c9SJonathan Lemon.Dv errno 407ad35a4c9SJonathan Lemonwill be set to indicate the error condition. 408ad35a4c9SJonathan LemonIf the time limit expires, then 409ad35a4c9SJonathan Lemon.Fn kevent 410ad35a4c9SJonathan Lemonreturns 0. 411ad35a4c9SJonathan Lemon.Sh ERRORS 412ad35a4c9SJonathan LemonThe 413af7b56f4SJohn-Mark Gurney.Fn kqueue 414af7b56f4SJohn-Mark Gurneyfunction fails if: 415af7b56f4SJohn-Mark Gurney.Bl -tag -width Er 416af7b56f4SJohn-Mark Gurney.It Bq Er ENOMEM 417af7b56f4SJohn-Mark GurneyThe kernel failed to allocate enough memory for the kernel queue. 418af7b56f4SJohn-Mark Gurney.It Bq Er EMFILE 419af7b56f4SJohn-Mark GurneyThe per-process descriptor table is full. 420af7b56f4SJohn-Mark Gurney.It Bq Er ENFILE 421af7b56f4SJohn-Mark GurneyThe system file table is full. 422af7b56f4SJohn-Mark Gurney.El 423af7b56f4SJohn-Mark Gurney.Pp 424af7b56f4SJohn-Mark GurneyThe 425ad35a4c9SJonathan Lemon.Fn kevent 426ad35a4c9SJonathan Lemonfunction fails if: 427ad35a4c9SJonathan Lemon.Bl -tag -width Er 428c23155a4SRuslan Ermilov.It Bq Er EACCES 429ad35a4c9SJonathan LemonThe process does not have permission to register a filter. 430ad35a4c9SJonathan Lemon.It Bq Er EFAULT 431ad35a4c9SJonathan LemonThere was an error reading or writing the 432ad35a4c9SJonathan Lemon.Va kevent 433ad35a4c9SJonathan Lemonstructure. 434ad35a4c9SJonathan Lemon.It Bq Er EBADF 435ad35a4c9SJonathan LemonThe specified descriptor is invalid. 436ad35a4c9SJonathan Lemon.It Bq Er EINTR 437ad35a4c9SJonathan LemonA signal was delivered before the timeout expired and before any 438ad35a4c9SJonathan Lemonevents were placed on the kqueue for return. 439ad35a4c9SJonathan Lemon.It Bq Er EINVAL 440ad35a4c9SJonathan LemonThe specified time limit or filter is invalid. 441b275c430SJonathan Lemon.It Bq Er ENOENT 442b275c430SJonathan LemonThe event could not be found to be modified or deleted. 443ad35a4c9SJonathan Lemon.It Bq Er ENOMEM 444ad35a4c9SJonathan LemonNo memory was available to register the event. 445ad35a4c9SJonathan Lemon.It Bq Er ESRCH 446ad35a4c9SJonathan LemonThe specified process to attach to does not exist. 447ad35a4c9SJonathan Lemon.El 448ad35a4c9SJonathan Lemon.Sh SEE ALSO 449ad35a4c9SJonathan Lemon.Xr aio_error 2 , 450ad35a4c9SJonathan Lemon.Xr aio_read 2 , 451ad35a4c9SJonathan Lemon.Xr aio_return 2 , 452ad35a4c9SJonathan Lemon.Xr poll 2 , 453ad35a4c9SJonathan Lemon.Xr read 2 , 454ad35a4c9SJonathan Lemon.Xr select 2 , 455ad35a4c9SJonathan Lemon.Xr sigaction 2 , 4563c63f48cSSheldon Hearn.Xr write 2 , 4573c63f48cSSheldon Hearn.Xr signal 3 458ad35a4c9SJonathan Lemon.Sh HISTORY 459ad35a4c9SJonathan LemonThe 460ad35a4c9SJonathan Lemon.Fn kqueue 461ad35a4c9SJonathan Lemonand 462ad35a4c9SJonathan Lemon.Fn kevent 463ad35a4c9SJonathan Lemonfunctions first appeared in 46455b8fbfbSJohn-Mark Gurney.Fx 4.1 . 4654451bb5dSJonathan Lemon.Sh AUTHORS 466ad35a4c9SJonathan LemonThe 467ad35a4c9SJonathan Lemon.Fn kqueue 468ad35a4c9SJonathan Lemonsystem and this manual page were written by 4694451bb5dSJonathan Lemon.An Jonathan Lemon Aq [email protected] . 470e585cdf0SJohn-Mark Gurney.Sh BUGS 4713c63f48cSSheldon HearnIt is currently not possible to watch a 4723c63f48cSSheldon Hearn.Xr vnode 9 4733c63f48cSSheldon Hearnthat resides on anything but 474e585cdf0SJohn-Mark Gurneya UFS file system. 475