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