]>
Commit | Line | Data |
---|---|---|
b0d623f7 | 1 | .\" |
04b8595b | 2 | .\" Copyright (c) 2008-2015 Apple Inc. All rights reserved. |
b0d623f7 A |
3 | .\" |
4 | .\" @APPLE_LICENSE_HEADER_START@ | |
5 | .\" | |
6 | .\" This file contains Original Code and/or Modifications of Original Code | |
7 | .\" as defined in and that are subject to the Apple Public Source License | |
8 | .\" Version 2.0 (the 'License'). You may not use this file except in | |
9 | .\" compliance with the License. Please obtain a copy of the License at | |
10 | .\" http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | .\" file. | |
12 | .\" | |
13 | .\" The Original Code and all software distributed under the License are | |
14 | .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | .\" Please see the License for the specific language governing rights and | |
19 | .\" limitations under the License. | |
20 | .\" | |
21 | .\" @APPLE_LICENSE_HEADER_END@ | |
22 | .\" | |
23 | .\" | |
55e303ae A |
24 | .\" Copyright (c) 2000 Jonathan Lemon |
25 | .\" All rights reserved. | |
26 | .\" | |
27 | .\" Redistribution and use in source and binary forms, with or without | |
28 | .\" modification, are permitted provided that the following conditions | |
29 | .\" are met: | |
30 | .\" 1. Redistributions of source code must retain the above copyright | |
31 | .\" notice, this list of conditions and the following disclaimer. | |
32 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
33 | .\" notice, this list of conditions and the following disclaimer in the | |
34 | .\" documentation and/or other materials provided with the distribution. | |
35 | .\" | |
36 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND | |
37 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
38 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
39 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
40 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
41 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
42 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
43 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
44 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
45 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
46 | .\" SUCH DAMAGE. | |
47 | .\" | |
48 | .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.32 2002/12/19 09:40:25 ru Exp $ | |
49 | .\" | |
b0d623f7 | 50 | .Dd October 21, 2008 |
55e303ae A |
51 | .Dt KQUEUE 2 |
52 | .Os | |
53 | .Sh NAME | |
54 | .Nm kqueue , | |
b0d623f7 | 55 | .Nm kevent , |
b0d623f7 | 56 | .Nm kevent64 |
3e170ce0 A |
57 | and |
58 | .Nm kevent_qos | |
55e303ae A |
59 | .Nd kernel event notification mechanism |
60 | .Sh LIBRARY | |
61 | .Lb libc | |
62 | .Sh SYNOPSIS | |
63 | .In sys/types.h | |
64 | .In sys/event.h | |
65 | .In sys/time.h | |
66 | .Ft int | |
67 | .Fn kqueue "void" | |
68 | .Ft int | |
69 | .Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout" | |
b0d623f7 A |
70 | .Ft int |
71 | .Fn kevent64 "int kq" "const struct kevent64_s *changelist" "int nchanges" "struct kevent64_s *eventlist" "int nevents" "unsigned int flags" "const struct timespec *timeout" | |
3e170ce0 A |
72 | .Ft int |
73 | .Fn kevent_qos "int kq" "const struct kevent_qos_s *changelist" "int nchanges" "struct kevent_qos_s *eventlist" "int nevents" "void *data_out" "size_t *data_available" "unsigned int flags" | |
55e303ae | 74 | .Fn EV_SET "&kev" ident filter flags fflags data udata |
b0d623f7 | 75 | .Fn EV_SET64 "&kev" ident filter flags fflags data udata "ext[0]" "ext[1]" |
3e170ce0 | 76 | .Fn EV_SET_QOS "&kev" ident filter flags qos udata fflags xflags data "ext[0]" "ext[1]" "ext[2]" "ext[3]" |
55e303ae A |
77 | .Sh DESCRIPTION |
78 | The | |
79 | .Fn kqueue | |
3e170ce0 | 80 | system call allocates a kqueue file descriptor. This file descriptor |
6d2010ae | 81 | provides a generic method of notifying the user when a kernel |
55e303ae A |
82 | event (kevent) happens or a condition holds, based on the results |
83 | of small pieces of kernel code termed filters. | |
3e170ce0 A |
84 | .Pp |
85 | A kevent is identified by an (ident, filter, and optional udata value) | |
86 | tuple. It specifies the interesting conditions to be notified about | |
87 | for that tuple. An (ident, filter, and optional udata value) tuple can | |
88 | only appear once in a given kqueue. | |
89 | Subsequent attempts to register the same tuple for a given kqueue | |
55e303ae A |
90 | will result in the replacement of the conditions being watched, |
91 | not an addition. | |
3e170ce0 A |
92 | Whether the udata value is considered as part of the tuple is controlled |
93 | by the EV_UDATA_SPECIFIC flag on the kevent. | |
55e303ae A |
94 | .Pp |
95 | The filter identified in a kevent is executed upon the initial | |
96 | registration of that event in order to detect whether a preexisting | |
97 | condition is present, and is also executed whenever an event is | |
98 | passed to the filter for evaluation. | |
99 | If the filter determines that the condition should be reported, | |
100 | then the kevent is placed on the kqueue for the user to retrieve. | |
101 | .Pp | |
102 | The filter is also run when the user attempts to retrieve the kevent | |
103 | from the kqueue. | |
104 | If the filter indicates that the condition that triggered | |
105 | the event no longer holds, the kevent is removed from the kqueue and | |
106 | is not returned. | |
107 | .Pp | |
108 | Multiple events which trigger the filter do not result in multiple | |
109 | kevents being placed on the kqueue; instead, the filter will aggregate | |
110 | the events into a single struct kevent. | |
111 | Calling | |
112 | .Fn close | |
113 | on a file descriptor will remove any kevents that reference the descriptor. | |
114 | .Pp | |
115 | The | |
116 | .Fn kqueue | |
117 | system call | |
118 | creates a new kernel event queue and returns a descriptor. | |
119 | The queue is not inherited by a child created with | |
120 | .Xr fork 2 . | |
121 | .Pp | |
122 | The | |
3e170ce0 | 123 | .Fn kevent, |
b0d623f7 | 124 | .Fn kevent64 |
3e170ce0 A |
125 | and |
126 | .Fn kevent_qos | |
b0d623f7 A |
127 | system calls |
128 | are used to register events with the queue, and return any pending | |
55e303ae A |
129 | events to the user. |
130 | The | |
131 | .Fa changelist | |
132 | argument | |
133 | is a pointer to an array of | |
3e170ce0 | 134 | .Va kevent, |
b0d623f7 | 135 | .Va kevent64_s |
3e170ce0 A |
136 | or |
137 | .Va kevent_qos_s | |
55e303ae A |
138 | structures, as defined in |
139 | .Aq Pa sys/event.h . | |
140 | All changes contained in the | |
141 | .Fa changelist | |
142 | are applied before any pending events are read from the queue. | |
143 | The | |
144 | .Fa nchanges | |
145 | argument | |
146 | gives the size of | |
147 | .Fa changelist . | |
148 | The | |
149 | .Fa eventlist | |
150 | argument | |
3e170ce0 A |
151 | is a pointer to an array of out |
152 | .Va kevent, | |
b0d623f7 | 153 | .Va kevent64_s |
3e170ce0 A |
154 | or |
155 | .Va kevent_qos_s | |
b0d623f7 | 156 | structures. |
55e303ae A |
157 | The |
158 | .Fa nevents | |
3e170ce0 | 159 | argument determines the size of |
55e303ae | 160 | .Fa eventlist . |
3e170ce0 A |
161 | If the KEVENT_FLAG_STACK_EVENTS flag is provided on the system call, |
162 | the eventlist array is filled in in stack order (starting in the | |
163 | highest available index) instead of typical array order. | |
164 | The | |
165 | .Fa out_data | |
166 | argument provides space for extra out data provided by specific filters. | |
167 | The | |
168 | .Fa data_available | |
169 | argument's contents specified the space available in the data pool on input, | |
170 | and contains the amount still remaining on output. | |
171 | If the KEVENT_FLAG_STACK_DATA flag is specified on the system call, | |
172 | the data is allocated from the pool in stack order instead of typical heap order. | |
55e303ae A |
173 | If |
174 | .Fa timeout | |
175 | is a non-NULL pointer, it specifies a maximum interval to wait | |
176 | for an event, which will be interpreted as a struct timespec. If | |
177 | .Fa timeout | |
b0d623f7 | 178 | is a NULL pointer, both |
55e303ae | 179 | .Fn kevent |
b0d623f7 A |
180 | and |
181 | .Fn kevent64 | |
182 | wait indefinitely. To effect a poll, the | |
3e170ce0 A |
183 | .Fa flags |
184 | argument to | |
185 | .Fn kevent64 | |
186 | or | |
187 | .Fn kevent_qos | |
188 | can include the KEVENT_FLAG_IMMEDIATE value to indicate an | |
189 | immediate timeout. Alternatively, the | |
55e303ae A |
190 | .Fa timeout |
191 | argument should be non-NULL, pointing to a zero-valued | |
192 | .Va timespec | |
193 | structure. The same array may be used for the | |
194 | .Fa changelist | |
195 | and | |
196 | .Fa eventlist . | |
197 | .Pp | |
198 | The | |
199 | .Fn EV_SET | |
200 | macro is provided for ease of initializing a | |
b0d623f7 A |
201 | .Va kevent |
202 | structure. Similarly, | |
203 | .Fn EV_SET64 | |
204 | initializes a | |
205 | .Va kevent64_s | |
3e170ce0 A |
206 | structure and |
207 | .Fn EV_SET_QOS | |
208 | initializes a | |
209 | .Va kevent_qos_s | |
b0d623f7 | 210 | structure. |
55e303ae A |
211 | .Pp |
212 | The | |
3e170ce0 | 213 | .Va kevent, |
b0d623f7 | 214 | .Va kevent64_s |
3e170ce0 A |
215 | and |
216 | .Va kevent_qos_s | |
b0d623f7 | 217 | structures are defined as: |
55e303ae A |
218 | .Bd -literal |
219 | struct kevent { | |
b0d623f7 A |
220 | uintptr_t ident; /* identifier for this event */ |
221 | int16_t filter; /* filter for event */ | |
222 | uint16_t flags; /* general flags */ | |
223 | uint32_t fflags; /* filter-specific flags */ | |
224 | intptr_t data; /* filter-specific data */ | |
225 | void *udata; /* opaque user data identifier */ | |
226 | }; | |
227 | ||
b0d623f7 A |
228 | struct kevent64_s { |
229 | uint64_t ident; /* identifier for this event */ | |
230 | int16_t filter; /* filter for event */ | |
231 | uint16_t flags; /* general flags */ | |
232 | uint32_t fflags; /* filter-specific flags */ | |
233 | int64_t data; /* filter-specific data */ | |
234 | uint64_t udata; /* opaque user data identifier */ | |
235 | uint64_t ext[2]; /* filter-specific extensions */ | |
55e303ae | 236 | }; |
3e170ce0 A |
237 | |
238 | struct kevent_qos_s { | |
239 | uint64_t ident; /* identifier for this event */ | |
240 | int16_t filter; /* filter for event */ | |
241 | uint16_t flags; /* general flags */ | |
242 | uint32_t qos; /* quality of service when servicing event */ | |
243 | uint64_t udata; /* opaque user data identifier */ | |
244 | uint32_t fflags; /* filter-specific flags */ | |
245 | uint32_t xflags; /* extra filter-specific flags */ | |
246 | int64_t data; /* filter-specific data */ | |
247 | uint64_t ext[4]; /* filter-specific extensions */ | |
248 | }; | |
55e303ae A |
249 | .Ed |
250 | .Pp | |
b0d623f7 A |
251 | ---- |
252 | .Pp | |
55e303ae | 253 | The fields of |
3e170ce0 | 254 | .Fa struct kevent, |
b0d623f7 | 255 | .Fa struct kevent64_s |
3e170ce0 A |
256 | and |
257 | .Fa struct kevent_qos_s | |
55e303ae A |
258 | are: |
259 | .Bl -tag -width XXXfilter | |
260 | .It ident | |
3e170ce0 | 261 | Value used to identify the source of the event. |
55e303ae A |
262 | The exact interpretation is determined by the attached filter, |
263 | but often is a file descriptor. | |
264 | .It filter | |
265 | Identifies the kernel filter used to process this event. The pre-defined | |
266 | system filters are described below. | |
267 | .It flags | |
268 | Actions to perform on the event. | |
269 | .It fflags | |
270 | Filter-specific flags. | |
271 | .It data | |
272 | Filter-specific data value. | |
273 | .It udata | |
3e170ce0 A |
274 | Opaque user-defined value passed through the kernel unchanged. It can |
275 | optionally be part of the uniquing decision of the kevent system | |
55e303ae A |
276 | .El |
277 | .Pp | |
b0d623f7 A |
278 | In addition, |
279 | .Fa struct kevent64_s | |
280 | contains: | |
281 | .Bl -tag -width XXXfilter | |
282 | .It ext[2] | |
283 | This field stores extensions for the event's filter. What type of extension depends on | |
284 | what type of filter is being used. | |
285 | .El | |
286 | .Pp | |
3e170ce0 A |
287 | In addition, |
288 | .Fa struct kevent_qos_s | |
289 | contains: | |
290 | .Bl -tag -width XXXfilter | |
291 | .It xflags | |
292 | Extra filter-specific flags. | |
293 | .It ext[4] | |
294 | The QoS variant provides twice as many extension values for filter-specific uses. | |
295 | .El | |
296 | .Pp | |
b0d623f7 A |
297 | ---- |
298 | .Pp | |
55e303ae A |
299 | The |
300 | .Va flags | |
301 | field can contain the following values: | |
302 | .Bl -tag -width XXXEV_ONESHOT | |
303 | .It EV_ADD | |
304 | Adds the event to the kqueue. Re-adding an existing event | |
305 | will modify the parameters of the original event, and not result | |
306 | in a duplicate entry. Adding an event automatically enables it, | |
307 | unless overridden by the EV_DISABLE flag. | |
308 | .It EV_ENABLE | |
309 | Permit | |
3e170ce0 | 310 | .Fn kevent, |
b0d623f7 | 311 | .Fn kevent64 |
3e170ce0 A |
312 | and |
313 | .Fn kevent_qos | |
55e303ae A |
314 | to return the event if it is triggered. |
315 | .It EV_DISABLE | |
316 | Disable the event so | |
3e170ce0 | 317 | .Fn kevent, |
b0d623f7 | 318 | .Fn kevent64 |
3e170ce0 A |
319 | and |
320 | .Fn kevent_qos | |
55e303ae A |
321 | will not return it. The filter itself is not disabled. |
322 | .It EV_DELETE | |
323 | Removes the event from the kqueue. Events which are attached to | |
324 | file descriptors are automatically deleted on the last close of | |
325 | the descriptor. | |
2d21ac55 A |
326 | .It EV_RECEIPT |
327 | This flag is useful for making bulk changes to a kqueue without draining any | |
328 | pending events. When passed as input, it forces EV_ERROR to always be returned. | |
6d2010ae | 329 | When a filter is successfully added, the |
2d21ac55 A |
330 | .Va data |
331 | field will be zero. | |
55e303ae A |
332 | .It EV_ONESHOT |
333 | Causes the event to return only the first occurrence of the filter | |
334 | being triggered. After the user retrieves the event from the kqueue, | |
335 | it is deleted. | |
336 | .It EV_CLEAR | |
337 | After the event is retrieved by the user, its state is reset. | |
338 | This is useful for filters which report state transitions | |
339 | instead of the current state. Note that some filters may automatically | |
340 | set this flag internally. | |
341 | .It EV_EOF | |
342 | Filters may set this flag to indicate filter-specific EOF condition. | |
04b8595b A |
343 | .It EV_OOBAND |
344 | Read filter on socket may set this flag to indicate the presence of out of | |
345 | band data on the descriptor. | |
55e303ae A |
346 | .It EV_ERROR |
347 | See | |
348 | .Sx RETURN VALUES | |
349 | below. | |
350 | .El | |
351 | .Pp | |
b0d623f7 A |
352 | ---- |
353 | .Pp | |
55e303ae A |
354 | The predefined system filters are listed below. |
355 | Arguments may be passed to and from the filter via the | |
3e170ce0 | 356 | .Va data, |
55e303ae | 357 | .Va fflags |
3e170ce0 A |
358 | and optionally |
359 | .Va xflags | |
b0d623f7 | 360 | fields in the |
3e170ce0 | 361 | .Va kevent, |
b0d623f7 | 362 | .Va kevent64_s |
3e170ce0 A |
363 | or |
364 | .Va kevent_qos_s | |
b0d623f7 A |
365 | structure. |
366 | .Bl -tag -width EVFILT_MACHPORT | |
55e303ae A |
367 | .It EVFILT_READ |
368 | Takes a file descriptor as the identifier, and returns whenever | |
369 | there is data available to read. | |
370 | The behavior of the filter is slightly different depending | |
371 | on the descriptor type. | |
372 | .Pp | |
373 | .Bl -tag -width 2n | |
374 | .It Sockets | |
375 | Sockets which have previously been passed to | |
376 | .Fn listen | |
377 | return when there is an incoming connection pending. | |
378 | .Va data | |
379 | contains the size of the listen backlog. | |
380 | .Pp | |
381 | Other socket descriptors return when there is data to be read, | |
382 | subject to the | |
383 | .Dv SO_RCVLOWAT | |
384 | value of the socket buffer. | |
385 | This may be overridden with a per-filter low water mark at the | |
386 | time the filter is added by setting the | |
387 | NOTE_LOWAT | |
388 | flag in | |
389 | .Va fflags , | |
390 | and specifying the new low water mark in | |
391 | .Va data . | |
3e170ce0 A |
392 | The derived per filter low water mark value is, however, bounded |
393 | by socket receive buffer's high and low water mark values. | |
55e303ae A |
394 | On return, |
395 | .Va data | |
396 | contains the number of bytes of protocol data available to read. | |
397 | .Pp | |
04b8595b A |
398 | The presence of EV_OOBAND in |
399 | .Va flags , | |
400 | indicates the presence of out of band data on the socket | |
401 | .Va data | |
402 | equal to the potential number of OOB bytes availble to read. | |
403 | .Pp | |
55e303ae A |
404 | If the read direction of the socket has shutdown, then the filter |
405 | also sets EV_EOF in | |
406 | .Va flags , | |
407 | and returns the socket error (if any) in | |
408 | .Va fflags . | |
409 | It is possible for EOF to be returned (indicating the connection is gone) | |
410 | while there is still data pending in the socket buffer. | |
411 | .It Vnodes | |
412 | Returns when the file pointer is not at the end of file. | |
413 | .Va data | |
414 | contains the offset from current position to end of file, | |
415 | and may be negative. | |
416 | .It "Fifos, Pipes" | |
3e170ce0 | 417 | Returns when there is data to read; |
55e303ae A |
418 | .Va data |
419 | contains the number of bytes available. | |
420 | .Pp | |
421 | When the last writer disconnects, the filter will set EV_EOF in | |
422 | .Va flags . | |
423 | This may be cleared by passing in EV_CLEAR, at which point the | |
424 | filter will resume waiting for data to become available before | |
425 | returning. | |
3e170ce0 A |
426 | .It "Device nodes" |
427 | Returns when there is data to read from the device; | |
428 | .Va data | |
429 | contains the number of bytes available. If the device does | |
430 | not support returning number of bytes, it will not allow the | |
431 | filter to be attached. However, if the NOTE_LOWAT flag is | |
432 | specified and the | |
433 | .Va data | |
434 | field contains 1 on input, those devices will attach - but | |
435 | cannot be relied upon to provide an accurate count of bytes | |
436 | to be read on output. | |
55e303ae A |
437 | .El |
438 | .It EVFILT_WRITE | |
439 | Takes a file descriptor as the identifier, and returns whenever | |
440 | it is possible to write to the descriptor. For sockets, pipes | |
441 | and fifos, | |
442 | .Va data | |
443 | will contain the amount of space remaining in the write buffer. | |
444 | The filter will set EV_EOF when the reader disconnects, and for | |
445 | the fifo case, this may be cleared by use of EV_CLEAR. | |
446 | Note that this filter is not supported for vnodes. | |
447 | .Pp | |
448 | For sockets, the low water mark and socket error handling is | |
449 | identical to the EVFILT_READ case. | |
450 | .It EVFILT_AIO | |
451 | This filter is currently unsupported. | |
452 | .\"The sigevent portion of the AIO request is filled in, with | |
453 | .\".Va sigev_notify_kqueue | |
454 | .\"containing the descriptor of the kqueue that the event should | |
455 | .\"be attached to, | |
456 | .\".Va sigev_value | |
457 | .\"containing the udata value, and | |
458 | .\".Va sigev_notify | |
459 | .\"set to SIGEV_KEVENT. | |
460 | .\"When the | |
461 | .\".Fn aio_* | |
462 | .\"system call is made, the event will be registered | |
463 | .\"with the specified kqueue, and the | |
464 | .\".Va ident | |
465 | .\"argument set to the | |
466 | .\".Fa struct aiocb | |
467 | .\"returned by the | |
468 | .\".Fn aio_* | |
469 | .\"system call. | |
470 | .\"The filter returns under the same conditions as aio_error. | |
471 | .\".Pp | |
472 | .\"Alternatively, a kevent structure may be initialized, with | |
473 | .\".Va ident | |
474 | .\"containing the descriptor of the kqueue, and the | |
475 | .\"address of the kevent structure placed in the | |
476 | .\".Va aio_lio_opcode | |
477 | .\"field of the AIO request. However, this approach will not work on | |
478 | .\"architectures with 64-bit pointers, and should be considered deprecated. | |
479 | .It EVFILT_VNODE | |
480 | Takes a file descriptor as the identifier and the events to watch for in | |
481 | .Va fflags , | |
482 | and returns when one or more of the requested events occurs on the descriptor. | |
483 | The events to monitor are: | |
484 | .Bl -tag -width XXNOTE_RENAME | |
485 | .It NOTE_DELETE | |
486 | The | |
487 | .Fn unlink | |
488 | system call | |
489 | was called on the file referenced by the descriptor. | |
490 | .It NOTE_WRITE | |
491 | A write occurred on the file referenced by the descriptor. | |
492 | .It NOTE_EXTEND | |
493 | The file referenced by the descriptor was extended. | |
494 | .It NOTE_ATTRIB | |
495 | The file referenced by the descriptor had its attributes changed. | |
496 | .It NOTE_LINK | |
497 | The link count on the file changed. | |
498 | .It NOTE_RENAME | |
499 | The file referenced by the descriptor was renamed. | |
500 | .It NOTE_REVOKE | |
501 | Access to the file was revoked via | |
502 | .Xr revoke 2 | |
503 | or the underlying fileystem was unmounted. | |
504 | .El | |
505 | .Pp | |
506 | On return, | |
507 | .Va fflags | |
3e170ce0 A |
508 | contains the filter-specific flags which are associated with |
509 | the triggered events seen by this filter. | |
55e303ae A |
510 | .It EVFILT_PROC |
511 | Takes the process ID to monitor as the identifier and the events to watch for | |
512 | in | |
513 | .Va fflags , | |
514 | and returns when the process performs one or more of the requested events. | |
515 | If a process can normally see another process, it can attach an event to it. | |
516 | The events to monitor are: | |
b0d623f7 | 517 | .Bl -tag -width NOTE_SIGNAL |
55e303ae A |
518 | .It NOTE_EXIT |
519 | The process has exited. | |
6d2010ae A |
520 | .It NOTE_EXITSTATUS |
521 | The process has exited and its exit status is in filter specific data. Valid only on child processes and to be used along with NOTE_EXIT. | |
55e303ae | 522 | .It NOTE_FORK |
2d21ac55 A |
523 | The process created a child process via |
524 | .Xr fork 2 | |
525 | or similar call. | |
55e303ae | 526 | .It NOTE_EXEC |
2d21ac55 | 527 | The process executed a new process via |
55e303ae A |
528 | .Xr execve 2 |
529 | or similar call. | |
2d21ac55 A |
530 | .It NOTE_SIGNAL |
531 | The process was sent a signal. Status can be checked via | |
532 | .Xr waitpid 2 | |
533 | or similar call. | |
534 | .It NOTE_REAP | |
535 | The process was reaped by the parent via | |
536 | .Xr wait 2 | |
39236c6e | 537 | or similar call. Deprecated, use NOTE_EXIT. |
55e303ae A |
538 | .El |
539 | .Pp | |
540 | On return, | |
541 | .Va fflags | |
542 | contains the events which triggered the filter. | |
543 | .It EVFILT_SIGNAL | |
544 | Takes the signal number to monitor as the identifier and returns | |
b0d623f7 | 545 | when the given signal is generated for the process. |
55e303ae A |
546 | This coexists with the |
547 | .Fn signal | |
548 | and | |
549 | .Fn sigaction | |
b0d623f7 A |
550 | facilities, and has a lower precedence. Only signals sent to the process, |
551 | not to a particular thread, will trigger the filter. The filter will record | |
55e303ae | 552 | all attempts to deliver a signal to a process, even if the signal has |
b0d623f7 | 553 | been marked as SIG_IGN. Event notification happens before normal |
55e303ae A |
554 | signal delivery processing. |
555 | .Va data | |
b0d623f7 | 556 | returns the number of times the signal has been generated since the last call to |
55e303ae A |
557 | .Fn kevent . |
558 | This filter automatically sets the EV_CLEAR flag internally. | |
b0d623f7 A |
559 | .It EVFILT_MACHPORT |
560 | Takes the name of a mach port, or port set, in | |
561 | .Va ident | |
3e170ce0 A |
562 | and waits until a message is enqueued on the port or port set. When a message |
563 | is detected, but not directly received by the kevent call, the name of the | |
564 | specific port where the message is enqueued is returned in | |
565 | .Va data . | |
566 | If | |
b0d623f7 | 567 | .Va fflags |
3e170ce0 A |
568 | contains MACH_RCV_MSG, the ext[0] and ext[1] flags are assumed to contain |
569 | a pointer to the buffer where the message is to be received and the size | |
570 | of the receive buffer, respectively. If MACH_RCV_MSG is specifed, yet the | |
571 | buffer size in ext[1] is zero, The space for the buffer may be carved out | |
572 | of the | |
573 | .Va | |
574 | data_out | |
575 | area provided to | |
576 | .Fn kevent_qos | |
577 | if there is enough space remaining there. | |
55e303ae | 578 | .It EVFILT_TIMER |
b0d623f7 A |
579 | Establishes an interval timer with the data |
580 | timer identified by | |
581 | .Va ident . | |
582 | When adding a timer, | |
583 | .Va data | |
584 | specifies the timeout period and | |
585 | .Va fflags | |
586 | can be set to one of the following: | |
587 | .Bl -tag -width NOTE_ABSOLUTE | |
588 | .It NOTE_SECONDS | |
589 | data is in seconds | |
590 | .It NOTE_USECONDS | |
591 | data is in microseconds | |
592 | .It NOTE_NSECONDS | |
593 | data is in nanoseconds | |
594 | .It NOTE_ABSOLUTE | |
595 | data is an absolute timeout | |
39236c6e A |
596 | .It NOTE_CRITICAL |
597 | system makes a best effort to fire this timer as scheduled. | |
598 | .It NOTE_BACKGROUND | |
599 | system has extra leeway to coalesce this timer. | |
600 | .It NOTE_LEEWAY | |
601 | ext[1] holds user-supplied slop in deadline for timer coalescing. | |
b0d623f7 A |
602 | .El |
603 | .Pp | |
604 | If fflags is not set, the default is milliseconds. The timer will be periodic unless EV_ONESHOT is specified. | |
605 | On return, | |
606 | .Va data | |
607 | contains the number of times the timeout has expired since the last call to | |
3e170ce0 A |
608 | .Fn kevent , |
609 | .Fn kevent64 | |
b0d623f7 | 610 | or |
3e170ce0 A |
611 | .Fn kevent_qos . |
612 | ||
b0d623f7 | 613 | This filter automatically sets the EV_CLEAR flag internally. |
b0d623f7 A |
614 | .El |
615 | .Pp | |
616 | ---- | |
617 | .Pp | |
618 | In the | |
619 | .Va ext[2] | |
620 | field of the | |
621 | .Va kevent64_s | |
622 | struture, | |
623 | .Va ext[0] | |
624 | is only used with the EVFILT_MACHPORT filter. | |
625 | With other filters, | |
626 | .Va ext[0] | |
627 | is passed through | |
628 | .Fn kevent64 | |
629 | much like | |
630 | .Va udata . | |
631 | .Va ext[1] | |
632 | can always be used like | |
633 | .Va udata . | |
634 | For the use of ext[0], see the EVFILT_MACHPORT filter above. | |
55e303ae A |
635 | .Sh RETURN VALUES |
636 | The | |
637 | .Fn kqueue | |
638 | system call | |
639 | creates a new kernel event queue and returns a file descriptor. | |
640 | If there was an error creating the kernel event queue, a value of -1 is | |
641 | returned and errno set. | |
642 | .Pp | |
643 | The | |
3e170ce0 | 644 | .Fn kevent , |
b0d623f7 | 645 | .Fn kevent64 |
3e170ce0 A |
646 | and |
647 | .Fn kevent_qos | |
b0d623f7 A |
648 | system calls |
649 | return the number of events placed in the | |
55e303ae A |
650 | .Fa eventlist , |
651 | up to the value given by | |
652 | .Fa nevents . | |
653 | If an error occurs while processing an element of the | |
654 | .Fa changelist | |
655 | and there is enough room in the | |
656 | .Fa eventlist , | |
657 | then the event will be placed in the | |
658 | .Fa eventlist | |
659 | with | |
660 | .Dv EV_ERROR | |
661 | set in | |
662 | .Va flags | |
663 | and the system error in | |
664 | .Va data . | |
665 | Otherwise, | |
666 | .Dv -1 | |
667 | will be returned, and | |
668 | .Dv errno | |
669 | will be set to indicate the error condition. | |
670 | If the time limit expires, then | |
3e170ce0 | 671 | .Fn kevent , |
b0d623f7 | 672 | .Fn kevent64 |
3e170ce0 A |
673 | and |
674 | .Fn kevent_qos | |
b0d623f7 | 675 | return 0. |
55e303ae A |
676 | .Sh ERRORS |
677 | The | |
678 | .Fn kqueue | |
679 | system call fails if: | |
680 | .Bl -tag -width Er | |
681 | .It Bq Er ENOMEM | |
682 | The kernel failed to allocate enough memory for the kernel queue. | |
683 | .It Bq Er EMFILE | |
684 | The per-process descriptor table is full. | |
685 | .It Bq Er ENFILE | |
686 | The system file table is full. | |
687 | .El | |
688 | .Pp | |
689 | The | |
690 | .Fn kevent | |
b0d623f7 A |
691 | and |
692 | .Fn kevent64 | |
693 | system calls fail if: | |
55e303ae A |
694 | .Bl -tag -width Er |
695 | .It Bq Er EACCES | |
696 | The process does not have permission to register a filter. | |
697 | .It Bq Er EFAULT | |
698 | There was an error reading or writing the | |
699 | .Va kevent | |
b0d623f7 A |
700 | or |
701 | .Va kevent64_s | |
55e303ae A |
702 | structure. |
703 | .It Bq Er EBADF | |
704 | The specified descriptor is invalid. | |
705 | .It Bq Er EINTR | |
706 | A signal was delivered before the timeout expired and before any | |
707 | events were placed on the kqueue for return. | |
708 | .It Bq Er EINVAL | |
709 | The specified time limit or filter is invalid. | |
710 | .It Bq Er ENOENT | |
711 | The event could not be found to be modified or deleted. | |
712 | .It Bq Er ENOMEM | |
713 | No memory was available to register the event. | |
714 | .It Bq Er ESRCH | |
715 | The specified process to attach to does not exist. | |
716 | .El | |
717 | .Sh SEE ALSO | |
718 | .Xr aio_error 2 , | |
719 | .Xr aio_read 2 , | |
720 | .Xr aio_return 2 , | |
721 | .Xr read 2 , | |
722 | .Xr select 2 , | |
723 | .Xr sigaction 2 , | |
724 | .Xr write 2 , | |
725 | .Xr signal 3 | |
726 | .Sh HISTORY | |
727 | The | |
728 | .Fn kqueue | |
729 | and | |
730 | .Fn kevent | |
731 | system calls first appeared in | |
732 | .Fx 4.1 . | |
733 | .Sh AUTHORS | |
734 | The | |
735 | .Fn kqueue | |
736 | system and this manual page were written by | |
737 | .An Jonathan Lemon Aq jlemon@FreeBSD.org . | |
738 | .Sh BUGS | |
739 | Not all filesystem types support kqueue-style notifications. | |
740 | And even some that do, like some remote filesystems, may only | |
741 | support a subset of the notification semantics described | |
742 | here. |