Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153470518
D6082.id15552.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D6082.id15552.diff
View Options
Index: lib/libc/sys/kqueue.2
===================================================================
--- lib/libc/sys/kqueue.2
+++ lib/libc/sys/kqueue.2
@@ -525,6 +525,64 @@
If the time limit expires, then
.Fn kevent
returns 0.
+.Sh EXAMPLES
+.Bd -literal -compact
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main(int argc, char **argv)
+{
+
+ struct kevent event; /* Event we want to monitor */
+ struct kevent tevent; /* Event triggered */
+ int kq, fd, ret;
+
+ if (argc != 2) {
+ printf("Usage: %s dir\n", argv[0]);
+ exit(EXIT_SUCCESS);
+ }
+
+ if ((fd = open(argv[1], O_RDONLY)) == -1) {
+ perror("open");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Create kqueue */
+ if ((kq = kqueue()) == -1) {
+ perror("queue");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Initialize kevent structure */
+ EV_SET(&event, fd, EVFILT_VNODE , EV_ADD | EV_ONESHOT, NOTE_WRITE, 0, NULL);
+
+ for (;;) {
+ /* Attach event to the kqueue and block until something happens */
+ ret = kevent(kq, &event, 1, &tevent, 1, NULL);
+ if (ret == -1) {
+ perror("kevent");
+ exit(EXIT_FAILURE);
+ } else if (ret > 0) {
+ if (event.flags & EV_ERROR) {
+ fprintf(stderr, "Event error: %s\n", strerror(event.data));
+ }
+ printf("Something was written in '%s'\n", argv[1]);
+ }
+ }
+
+ /* NOTREACHED */
+ close(fd);
+ exit(EXIT_SUCCESS);
+
+}
+.Ed
.Sh ERRORS
The
.Fn kqueue
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 22, 8:41 AM (16 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31965769
Default Alt Text
D6082.id15552.diff (1 KB)
Attached To
Mode
D6082: Bug 196844 - [patch][doc] Add EXAMPLES section to kqueue(2) man page
Attached
Detach File
Event Timeline
Log In to Comment