xref: /freebsd/lib/libsys/kqueue.2 (revision 783d3ff6d7fae619db8a7990b8a6387de0c677b5)
1.\" Copyright (c) 2000 Jonathan Lemon
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd March 26, 2023
26.Dt KQUEUE 2
27.Os
28.Sh NAME
29.Nm kqueue ,
30.Nm kevent
31.Nd kernel event notification mechanism
32.Sh LIBRARY
33.Lb libc
34.Sh SYNOPSIS
35.In sys/event.h
36.Ft int
37.Fn kqueue "void"
38.Ft int
39.Fn kqueuex "u_int flags"
40.Ft int
41.Fo kevent
42.Fa "int kq"
43.Fa "const struct kevent *changelist"
44.Fa "int nchanges"
45.Fa "struct kevent *eventlist"
46.Fa "int nevents"
47.Fa "const struct timespec *timeout"
48.Fc
49.Fn EV_SET "kev" ident filter flags fflags data udata
50.Sh DESCRIPTION
51The
52.Fn kqueue
53system call
54provides a generic method of notifying the user when an event
55happens or a condition holds, based on the results of small
56pieces of kernel code termed filters.
57A kevent is identified by the (ident, filter) pair; there may only
58be one unique kevent per kqueue.
59.Pp
60The filter is executed upon the initial registration of a kevent
61in order to detect whether a preexisting condition is present, and is also
62executed whenever an event is passed to the filter for evaluation.
63If the filter determines that the condition should be reported,
64then the kevent is placed on the kqueue for the user to retrieve.
65.Pp
66The filter is also run when the user attempts to retrieve the kevent
67from the kqueue.
68If the filter indicates that the condition that triggered
69the event no longer holds, the kevent is removed from the kqueue and
70is not returned.
71.Pp
72Multiple events which trigger the filter do not result in multiple
73kevents being placed on the kqueue; instead, the filter will aggregate
74the events into a single struct kevent.
75Calling
76.Fn close
77on a file descriptor will remove any kevents that reference the descriptor.
78.Pp
79The
80.Fn kqueue
81system call
82creates a new kernel event queue and returns a descriptor.
83The queue is not inherited by a child created with
84.Xr fork 2 .
85However, if
86.Xr rfork 2
87is called without the
88.Dv RFFDG
89flag, then the descriptor table is shared,
90which will allow sharing of the kqueue between two processes.
91.Pp
92The
93.Fn kqueuex
94system call also creates a new kernel event queue, and additionally takes
95the
96.Fa flags
97argument, which is a bitwise-inclusive OR of the following flags:
98.Bl -tag -width "KQUEUE_CLOEXEC"
99.It Fa KQUEUE_CLOEXEC
100The returned file descriptor is automatically closed on
101.Xr execve 2
102.El
103The
104.Ql fd = kqueue()
105call is equivalent to
106.Ql fd = kqueuex(0) .
107.Pp
108For compatibility with
109.Nx ,
110the
111.Fn kqueue1
112function is provided, which accepts the
113.Dv O_CLOEXEC
114flag with the expected semantic.
115.Pp
116The
117.Fn kevent
118system call
119is used to register events with the queue, and return any pending
120events to the user.
121The
122.Fa changelist
123argument
124is a pointer to an array of
125.Va kevent
126structures, as defined in
127.In sys/event.h .
128All changes contained in the
129.Fa changelist
130are applied before any pending events are read from the queue.
131The
132.Fa nchanges
133argument
134gives the size of
135.Fa changelist .
136The
137.Fa eventlist
138argument
139is a pointer to an array of kevent structures.
140The
141.Fa nevents
142argument
143determines the size of
144.Fa eventlist .
145When
146.Fa nevents
147is zero,
148.Fn kevent
149will return immediately even if there is a
150.Fa timeout
151specified unlike
152.Xr select 2 .
153If
154.Fa timeout
155is a non-NULL pointer, it specifies a maximum interval to wait
156for an event, which will be interpreted as a struct timespec.
157If
158.Fa timeout
159is a NULL pointer,
160.Fn kevent
161waits indefinitely.
162To effect a poll, the
163.Fa timeout
164argument should be non-NULL, pointing to a zero-valued
165.Va timespec
166structure.
167The same array may be used for the
168.Fa changelist
169and
170.Fa eventlist .
171.Pp
172The
173.Fn EV_SET
174macro is provided for ease of initializing a
175kevent structure.
176.Pp
177The
178.Va kevent
179structure is defined as:
180.Bd -literal
181struct kevent {
182	uintptr_t  ident;	/* identifier for this event */
183	short	  filter;	/* filter for event */
184	u_short	  flags;	/* action flags for kqueue */
185	u_int	  fflags;	/* filter flag value */
186	int64_t   data;		/* filter data value */
187	void	  *udata;	/* opaque user data identifier */
188	uint64_t  ext[4];	/* extensions */
189};
190.Ed
191.Pp
192The fields of
193.Fa struct kevent
194are:
195.Bl -tag -width "Fa filter"
196.It Fa ident
197Value used to identify this event.
198The exact interpretation is determined by the attached filter,
199but often is a file descriptor.
200.It Fa filter
201Identifies the kernel filter used to process this event.
202The pre-defined
203system filters are described below.
204.It Fa flags
205Actions to perform on the event.
206.It Fa fflags
207Filter-specific flags.
208.It Fa data
209Filter-specific data value.
210.It Fa udata
211Opaque user-defined value passed through the kernel unchanged.
212.It Fa ext
213Extended data passed to and from kernel.
214The
215.Fa ext[0]
216and
217.Fa ext[1]
218members use is defined by the filter.
219If the filter does not use them, the members are copied unchanged.
220The
221.Fa ext[2]
222and
223.Fa ext[3]
224members are always passed through the kernel as-is,
225making additional context available to application.
226.El
227.Pp
228The
229.Va flags
230field can contain the following values:
231.Bl -tag -width EV_DISPATCH
232.It Dv EV_ADD
233Adds the event to the kqueue.
234Re-adding an existing event
235will modify the parameters of the original event, and not result
236in a duplicate entry.
237Adding an event automatically enables it,
238unless overridden by the EV_DISABLE flag.
239.It Dv EV_ENABLE
240Permit
241.Fn kevent
242to return the event if it is triggered.
243.It Dv EV_DISABLE
244Disable the event so
245.Fn kevent
246will not return it.
247The filter itself is not disabled.
248.It Dv EV_DISPATCH
249Disable the event source immediately after delivery of an event.
250See
251.Dv EV_DISABLE
252above.
253.It Dv EV_DELETE
254Removes the event from the kqueue.
255Events which are attached to
256file descriptors are automatically deleted on the last close of
257the descriptor.
258.It Dv EV_RECEIPT
259This flag is useful for making bulk changes to a kqueue without draining
260any pending events.
261When passed as input, it forces
262.Dv EV_ERROR
263to always be returned.
264When a filter is successfully added the
265.Va data
266field will be zero.
267Note that if this flag is encountered and there is no remaining space in
268.Fa eventlist
269to hold the
270.Dv EV_ERROR
271event, then subsequent changes will not get processed.
272.It Dv EV_ONESHOT
273Causes the event to return only the first occurrence of the filter
274being triggered.
275After the user retrieves the event from the kqueue,
276it is deleted.
277.It Dv EV_CLEAR
278After the event is retrieved by the user, its state is reset.
279This is useful for filters which report state transitions
280instead of the current state.
281Note that some filters may automatically
282set this flag internally.
283.It Dv EV_EOF
284Filters may set this flag to indicate filter-specific EOF condition.
285.It Dv EV_ERROR
286See
287.Sx RETURN VALUES
288below.
289.It Dv EV_KEEPUDATA
290Causes
291.Fn kevent
292to leave unchanged any
293.Fa udata
294associated with an existing event.
295This allows other aspects of the event to be modified without requiring the
296caller to know the
297.Fa udata
298value presently associated.
299This is especially useful with
300.Dv NOTE_TRIGGER
301or flags like
302.Dv EV_ENABLE .
303This flag may not be used with
304.Dv EV_ADD .
305.El
306.Pp
307The predefined system filters are listed below.
308Arguments may be passed to and from the filter via the
309.Va fflags
310and
311.Va data
312fields in the kevent structure.
313.Bl -tag -width "Dv EVFILT_PROCDESC"
314.It Dv EVFILT_READ
315Takes a descriptor as the identifier, and returns whenever
316there is data available to read.
317The behavior of the filter is slightly different depending
318on the descriptor type.
319.Bl -tag -width 2n
320.It Sockets
321Sockets which have previously been passed to
322.Xr listen 2
323return when there is an incoming connection pending.
324.Va data
325contains the size of the listen backlog.
326.Pp
327Other socket descriptors return when there is data to be read,
328subject to the
329.Dv SO_RCVLOWAT
330value of the socket buffer.
331This may be overridden with a per-filter low water mark at the
332time the filter is added by setting the
333.Dv NOTE_LOWAT
334flag in
335.Va fflags ,
336and specifying the new low water mark in
337.Va data .
338On return,
339.Va data
340contains the number of bytes of protocol data available to read.
341.Pp
342If the read direction of the socket has shutdown, then the filter
343also sets
344.Dv EV_EOF
345in
346.Va flags ,
347and returns the socket error (if any) in
348.Va fflags .
349It is possible for EOF to be returned (indicating the connection is gone)
350while there is still data pending in the socket buffer.
351.It Vnodes
352Returns when the file pointer is not at the end of file.
353.Va data
354contains the offset from current position to end of file,
355and may be negative.
356.Pp
357This behavior is different from
358.Xr poll 2 ,
359where read events are triggered for regular files unconditionally.
360This event can be triggered unconditionally by setting the
361.Dv NOTE_FILE_POLL
362flag in
363.Va fflags .
364.It "Fifos, Pipes"
365Returns when the there is data to read;
366.Va data
367contains the number of bytes available.
368.Pp
369When the last writer disconnects, the filter will set
370.Dv EV_EOF
371in
372.Va flags .
373This will be cleared by the filter when a new writer connects,
374at which point the
375filter will resume waiting for data to become available before
376returning.
377.It "BPF devices"
378Returns when the BPF buffer is full, the BPF timeout has expired, or
379when the BPF has
380.Dq immediate mode
381enabled and there is any data to read;
382.Va data
383contains the number of bytes available.
384.It Eventfds
385Returns when the counter is greater than 0;
386.Va data
387contains the counter value, which must be cast to
388.Vt uint64_t .
389.It Kqueues
390Returns when pending events are present on the queue;
391.Va data
392contains the number of events available.
393.El
394.It Dv EVFILT_WRITE
395Takes a descriptor as the identifier, and returns whenever
396it is possible to write to the descriptor.
397For sockets, pipes
398and fifos,
399.Va data
400will contain the amount of space remaining in the write buffer.
401The filter will set
402.Dv EV_EOF
403when the reader disconnects, and for the fifo case, this will be cleared
404when a new reader connects.
405Note that this filter is not supported for vnodes.
406.Pp
407For sockets, the low water mark and socket error handling is
408identical to the
409.Dv EVFILT_READ
410case.
411.Pp
412For eventfds,
413.Va data
414will contain the maximum value that can be added to the counter
415without blocking.
416.Pp
417For BPF devices, when the descriptor is attached to an interface the filter
418always indicates that it is possible to write and
419.Va data
420will contain the MTU size of the underlying interface.
421.It Dv EVFILT_EMPTY
422Takes a descriptor as the identifier, and returns whenever
423there is no remaining data in the write buffer.
424.It Dv EVFILT_AIO
425Events for this filter are not registered with
426.Fn kevent
427directly but are registered via the
428.Va aio_sigevent
429member of an asynchronous I/O request when it is scheduled via an
430asynchronous I/O system call such as
431.Fn aio_read .
432The filter returns under the same conditions as
433.Fn aio_error .
434For more details on this filter see
435.Xr sigevent 3 and
436.Xr aio 4 .
437.It Dv EVFILT_VNODE
438Takes a file descriptor as the identifier and the events to watch for in
439.Va fflags ,
440and returns when one or more of the requested events occurs on the descriptor.
441The events to monitor are:
442.Bl -tag -width "Dv NOTE_CLOSE_WRITE"
443.It Dv NOTE_ATTRIB
444The file referenced by the descriptor had its attributes changed.
445.It Dv NOTE_CLOSE
446A file descriptor referencing the monitored file, was closed.
447The closed file descriptor did not have write access.
448.It Dv NOTE_CLOSE_WRITE
449A file descriptor referencing the monitored file, was closed.
450The closed file descriptor had write access.
451.Pp
452This note, as well as
453.Dv NOTE_CLOSE ,
454are not activated when files are closed forcibly by
455.Xr unmount 2 or
456.Xr revoke 2 .
457Instead,
458.Dv NOTE_REVOKE
459is sent for such events.
460.It Dv NOTE_DELETE
461The
462.Fn unlink
463system call was called on the file referenced by the descriptor.
464.It Dv NOTE_EXTEND
465For regular file, the file referenced by the descriptor was extended.
466.Pp
467For directory, reports that a directory entry was added or removed,
468as the result of rename operation.
469The
470.Dv NOTE_EXTEND
471event is not reported when a name is changed inside the directory.
472.It Dv NOTE_LINK
473The link count on the file changed.
474In particular, the
475.Dv NOTE_LINK
476event is reported if a subdirectory was created or deleted inside
477the directory referenced by the descriptor.
478.It Dv NOTE_OPEN
479The file referenced by the descriptor was opened.
480.It Dv NOTE_READ
481A read occurred on the file referenced by the descriptor.
482.It Dv NOTE_RENAME
483The file referenced by the descriptor was renamed.
484.It Dv NOTE_REVOKE
485Access to the file was revoked via
486.Xr revoke 2
487or the underlying file system was unmounted.
488.It Dv NOTE_WRITE
489A write occurred on the file referenced by the descriptor.
490.El
491.Pp
492On return,
493.Va fflags
494contains the events which triggered the filter.
495.It Dv EVFILT_PROC
496Takes the process ID to monitor as the identifier and the events to watch for
497in
498.Va fflags ,
499and returns when the process performs one or more of the requested events.
500If a process can normally see another process, it can attach an event to it.
501The events to monitor are:
502.Bl -tag -width "Dv NOTE_TRACKERR"
503.It Dv NOTE_EXIT
504The process has exited.
505The exit status will be stored in
506.Va data
507in the same format as the status returned by
508.Xr wait 2 .
509.It Dv NOTE_FORK
510The process has called
511.Fn fork .
512.It Dv NOTE_EXEC
513The process has executed a new process via
514.Xr execve 2
515or a similar call.
516.It Dv NOTE_TRACK
517Follow a process across
518.Fn fork
519calls.
520The parent process registers a new kevent to monitor the child process
521using the same
522.Va fflags
523as the original event.
524The child process will signal an event with
525.Dv NOTE_CHILD
526set in
527.Va fflags
528and the parent PID in
529.Va data .
530.Pp
531If the parent process fails to register a new kevent
532.Pq usually due to resource limitations ,
533it will signal an event with
534.Dv NOTE_TRACKERR
535set in
536.Va fflags ,
537and the child process will not signal a
538.Dv NOTE_CHILD
539event.
540.El
541.Pp
542On return,
543.Va fflags
544contains the events which triggered the filter.
545.It Dv EVFILT_PROCDESC
546Takes the process descriptor created by
547.Xr pdfork 2
548to monitor as the identifier and the events to watch for in
549.Va fflags ,
550and returns when the associated process performs one or more of the
551requested events.
552The events to monitor are:
553.Bl -tag -width "Dv NOTE_EXIT"
554.It Dv NOTE_EXIT
555The process has exited.
556The exit status will be stored in
557.Va data .
558.El
559.Pp
560On return,
561.Va fflags
562contains the events which triggered the filter.
563.It Dv EVFILT_SIGNAL
564Takes the signal number to monitor as the identifier and returns
565when the given signal is delivered to the process.
566This coexists with the
567.Fn signal
568and
569.Fn sigaction
570facilities, and has a lower precedence.
571The filter will record
572all attempts to deliver a signal to a process, even if the signal has
573been marked as
574.Dv SIG_IGN ,
575except for the
576.Dv SIGCHLD
577signal, which, if ignored, will not be recorded by the filter.
578Event notification happens after normal
579signal delivery processing.
580.Va data
581returns the number of times the signal has occurred since the last call to
582.Fn kevent .
583This filter automatically sets the
584.Dv EV_CLEAR
585flag internally.
586.It Dv EVFILT_TIMER
587Establishes an arbitrary timer identified by
588.Va ident .
589When adding a timer,
590.Va data
591specifies the moment to fire the timer (for
592.Dv NOTE_ABSTIME )
593or the timeout period.
594The timer will be periodic unless
595.Dv EV_ONESHOT
596or
597.Dv NOTE_ABSTIME
598is specified.
599On return,
600.Va data
601contains the number of times the timeout has expired since the last call to
602.Fn kevent .
603For non-monotonic timers, this filter automatically sets the
604.Dv EV_CLEAR
605flag internally.
606.Pp
607The filter accepts the following flags in the
608.Va fflags
609argument:
610.Bl -tag -width "Dv NOTE_MSECONDS"
611.It Dv NOTE_SECONDS
612.Va data
613is in seconds.
614.It Dv NOTE_MSECONDS
615.Va data
616is in milliseconds.
617.It Dv NOTE_USECONDS
618.Va data
619is in microseconds.
620.It Dv NOTE_NSECONDS
621.Va data
622is in nanoseconds.
623.It Dv NOTE_ABSTIME
624The specified expiration time is absolute.
625.El
626.Pp
627If
628.Va fflags
629is not set, the default is milliseconds.
630On return,
631.Va fflags
632contains the events which triggered the filter.
633.Pp
634Periodic timers with a specified timeout of 0 will be silently adjusted to
635timeout after 1 of the time units specified by the requested precision in
636.Va fflags .
637If an absolute time is specified that has already passed, then it is treated as
638if the current time were specified and the event will fire as soon as possible.
639.Pp
640If an existing timer is re-added, the existing timer will be
641effectively canceled (throwing away any undelivered record of previous
642timer expiration) and re-started using the new parameters contained in
643.Va data
644and
645.Va fflags .
646.Pp
647There is a system wide limit on the number of timers
648which is controlled by the
649.Va kern.kq_calloutmax
650sysctl.
651.It Dv EVFILT_USER
652Establishes a user event identified by
653.Va ident
654which is not associated with any kernel mechanism but is triggered by
655user level code.
656The lower 24 bits of the
657.Va fflags
658may be used for user defined flags and manipulated using the following:
659.Bl -tag -width "Dv NOTE_FFLAGSMASK"
660.It Dv NOTE_FFNOP
661Ignore the input
662.Va fflags .
663.It Dv NOTE_FFAND
664Bitwise AND
665.Va fflags .
666.It Dv NOTE_FFOR
667Bitwise OR
668.Va fflags .
669.It Dv NOTE_FFCOPY
670Copy
671.Va fflags .
672.It Dv NOTE_FFCTRLMASK
673Control mask for
674.Va fflags .
675.It Dv NOTE_FFLAGSMASK
676User defined flag mask for
677.Va fflags .
678.El
679.Pp
680A user event is triggered for output with the following:
681.Bl -tag -width "Dv NOTE_FFLAGSMASK"
682.It Dv NOTE_TRIGGER
683Cause the event to be triggered.
684.El
685.Pp
686On return,
687.Va fflags
688contains the users defined flags in the lower 24 bits.
689.El
690.Sh CANCELLATION BEHAVIOUR
691If
692.Fa nevents
693is non-zero, i.e., the function is potentially blocking, the call
694is a cancellation point.
695Otherwise, i.e., if
696.Fa nevents
697is zero, the call is not cancellable.
698Cancellation can only occur before any changes are made to the kqueue,
699or when the call was blocked and no changes to the queue were requested.
700.Sh RETURN VALUES
701The
702.Fn kqueue
703system call
704creates a new kernel event queue and returns a file descriptor.
705If there was an error creating the kernel event queue, a value of -1 is
706returned and errno set.
707.Pp
708The
709.Fn kevent
710system call
711returns the number of events placed in the
712.Fa eventlist ,
713up to the value given by
714.Fa nevents .
715If an error occurs while processing an element of the
716.Fa changelist
717and there is enough room in the
718.Fa eventlist ,
719then the event will be placed in the
720.Fa eventlist
721with
722.Dv EV_ERROR
723set in
724.Va flags
725and the system error in
726.Va data .
727Otherwise,
728.Dv -1
729will be returned, and
730.Dv errno
731will be set to indicate the error condition.
732If the time limit expires, then
733.Fn kevent
734returns 0.
735.Sh EXAMPLES
736.Bd -literal -compact
737#include <sys/event.h>
738#include <err.h>
739#include <fcntl.h>
740#include <stdio.h>
741#include <stdlib.h>
742#include <string.h>
743
744int
745main(int argc, char **argv)
746{
747    struct kevent event;    /* Event we want to monitor */
748    struct kevent tevent;   /* Event triggered */
749    int kq, fd, ret;
750
751    if (argc != 2)
752	err(EXIT_FAILURE, "Usage: %s path\en", argv[0]);
753    fd = open(argv[1], O_RDONLY);
754    if (fd == -1)
755	err(EXIT_FAILURE, "Failed to open '%s'", argv[1]);
756
757    /* Create kqueue. */
758    kq = kqueue();
759    if (kq == -1)
760	err(EXIT_FAILURE, "kqueue() failed");
761
762    /* Initialize kevent structure. */
763    EV_SET(&event, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE,
764	0, NULL);
765    /* Attach event to the kqueue. */
766    ret = kevent(kq, &event, 1, NULL, 0, NULL);
767    if (ret == -1)
768	err(EXIT_FAILURE, "kevent register");
769
770    for (;;) {
771	/* Sleep until something happens. */
772	ret = kevent(kq, NULL, 0, &tevent, 1, NULL);
773	if (ret == -1) {
774	    err(EXIT_FAILURE, "kevent wait");
775	} else if (ret > 0) {
776	    if (tevent.flags & EV_ERROR)
777		errx(EXIT_FAILURE, "Event error: %s", strerror(event.data));
778	    else
779		printf("Something was written in '%s'\en", argv[1]);
780	}
781    }
782
783    /* kqueues are destroyed upon close() */
784    (void)close(kq);
785    (void)close(fd);
786}
787.Ed
788.Sh ERRORS
789The
790.Fn kqueue
791system call fails if:
792.Bl -tag -width Er
793.It Bq Er ENOMEM
794The kernel failed to allocate enough memory for the kernel queue.
795.It Bq Er ENOMEM
796The
797.Dv RLIMIT_KQUEUES
798rlimit
799(see
800.Xr getrlimit 2 )
801for the current user would be exceeded.
802.It Bq Er EMFILE
803The per-process descriptor table is full.
804.It Bq Er ENFILE
805The system file table is full.
806.El
807.Pp
808The
809.Fn kevent
810system call fails if:
811.Bl -tag -width Er
812.It Bq Er EACCES
813The process does not have permission to register a filter.
814.It Bq Er EFAULT
815There was an error reading or writing the
816.Va kevent
817structure.
818.It Bq Er EBADF
819The specified descriptor is invalid.
820.It Bq Er EINTR
821A signal was delivered before the timeout expired and before any
822events were placed on the kqueue for return.
823.It Bq Er EINTR
824A cancellation request was delivered to the thread, but not yet handled.
825.It Bq Er EINVAL
826The specified time limit or filter is invalid.
827.It Bq Er EINVAL
828The specified length of the event or change lists is negative.
829.It Bq Er ENOENT
830The event could not be found to be modified or deleted.
831.It Bq Er ENOMEM
832No memory was available to register the event
833or, in the special case of a timer, the maximum number of
834timers has been exceeded.
835This maximum is configurable via the
836.Va kern.kq_calloutmax
837sysctl.
838.It Bq Er ESRCH
839The specified process to attach to does not exist.
840.El
841.Pp
842When
843.Fn kevent
844call fails with
845.Er EINTR
846error, all changes in the
847.Fa changelist
848have been applied.
849.Sh SEE ALSO
850.Xr aio_error 2 ,
851.Xr aio_read 2 ,
852.Xr aio_return 2 ,
853.Xr poll 2 ,
854.Xr read 2 ,
855.Xr select 2 ,
856.Xr sigaction 2 ,
857.Xr write 2 ,
858.Xr pthread_setcancelstate 3 ,
859.Xr signal 3
860.Rs
861.%A Jonathan Lemon
862.%T "Kqueue: A Generic and Scalable Event Notification Facility"
863.%I USENIX Association
864.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference
865.%D June 25-30, 2001
866.\".http://www.usenix.org/event/usenix01/freenix01/full_papers/lemon/lemon.pdf
867.Re
868.Sh HISTORY
869The
870.Fn kqueue
871and
872.Fn kevent
873system calls first appeared in
874.Fx 4.1 .
875.Sh AUTHORS
876The
877.Fn kqueue
878system and this manual page were written by
879.An Jonathan Lemon Aq Mt jlemon@FreeBSD.org .
880.Sh BUGS
881.Pp
882In versions older than
883.Fx 12.0 ,
884.In sys/event.h
885failed to parse without including
886.In sys/types.h
887manually.
888