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