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