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