Questions tagged [kqueue]

Kqueue is a scalable event notification interface introduced in FreeBSD 4.1,[1] also supported in NetBSD, OpenBSD, DragonflyBSD, and Mac OS X.

Kqueue provides efficient input and output event pipelines between the kernel and userland. Thus, it is possible to modify event filters as well as receive pending events while using only a single system call to kevent per main event loop iteration. This contrasts with older traditional polling system calls such as poll and select which are less efficient, especially when polling for events on a large number of file descriptors.

Kqueue does not only handle file descriptor events but is also used for various other notifications such as file modification monitoring, signals, asynchronous I/O events (AIO), child process state change monitoring and timers which support nanosecond resolution.

129 questions
31
votes
4 answers

File-level filesystem change notification in Mac OS X

I want my code to be notified when any file under (either directly or indirectly) a given directory is modified. By "modified", I mean I want my code to be notified whenever a file's contents are altered, it's renamed, or it's deleted; or if a new…
Paul J. Lucas
  • 6,895
  • 6
  • 44
  • 88
18
votes
1 answer

What are the underlying differences among select, epoll, kqueue, and evport?

I am reading Redis recently. Redis implements a simple event-driven library based on I/O multiplexing. Redis says it would choose the best multiplexing supported by the system, and gives the following code: /* Include the best multiplexing layer…
Min Fu
  • 789
  • 1
  • 6
  • 16
13
votes
2 answers

Does OS X not support epoll function?

I'm learning to use epoll function. But my OS X, Mountain Lion doesn't have a header file, sys/epoll.h. I'd like to use epoll function on OS X. How Can I use epoll function?
inherithandle
  • 2,614
  • 4
  • 31
  • 53
12
votes
2 answers

Watch directory for file changes

I want to monitor a directory (of thousands of files, with about 5 levels of sub directories) for when files are changed. I know I can use the FSEvents API to monitor a directory for when files change inside that directory, but I can't seem to…
v0idless
  • 948
  • 2
  • 11
  • 24
11
votes
2 answers

Writing a file with vim doesn't fire a file change event on OS X

I am using watchdog to monitor .less file change events on OS X. If I change the contents of a .less file with TextMate or Sublime Text the modification event is captured. However, if I edit the content with vim no file modification event is fired…
John Keyes
  • 5,479
  • 1
  • 29
  • 48
11
votes
1 answer

How to properly wait for an event/process to finish not being the parent?

I am using GO to check if a process (not been parent) has ben terminated, basically something like the pwait command in FreeBSD but written in go. Currently I am trying a for loop with a kill -0, but I notice that the CPU usage is very high 99% with…
nbari
  • 25,603
  • 10
  • 76
  • 131
11
votes
1 answer

revisiting "how do you use aio and epoll together"

following the discussion at How do you use AIO and epoll together in a single event loop?. There are in fact 2 "aio" APIs in linux. There's POSIX aio (the aio_* family of functions), included in glibc and libaio developed I believe by RedHat (?),…
user237419
  • 8,829
  • 4
  • 31
  • 38
9
votes
1 answer

What is the optimal way to monitor changes in a directory with a kqueue()?

OK: I'm implementing File Sharing in an iPhone OS app, and of course this means filesystem monitoring. Yay! Basically, the OS copies and/or deletes from and to a directory I can access when the user manipulates files into my app's section in iTunes.…
millenomi
  • 6,569
  • 4
  • 31
  • 34
8
votes
2 answers

Watchdog (osx) not notifying on remote network changes

I'm using Watchdog to monitor a network directory, non-recursive, for a specific pattern of files to be created over time. The issue I am seeing is that while it works fantastic when I test locally, if I make changes to the monitored directory from…
jdi
  • 90,542
  • 19
  • 167
  • 203
7
votes
2 answers

How do I replace select() with kevent() for higher performance?

From the Kqueue Wikipedia Page: Kqueue provides efficient input and output event pipelines between the kernel and userland. Thus, it is possible to modify event filters as well as receive pending events while using only a single system call to…
Nektarios
  • 10,173
  • 8
  • 63
  • 93
7
votes
2 answers

How to monitor file change on iOS platform?

i find that there are some libraries to monitor file changes on mac,for example:https://github.com/bdkjones/VDKQueue but i failed to find a library to monitor file changes on ios platform. could anybody tell me how to monitor file changes in objc…
TinyMonk
  • 204
  • 2
  • 6
7
votes
1 answer

Use kqueue to respond to more than one event type

When an event is registered with kqueue an ID relating to that event type is supplied; for example a file descriptor is used to identify a file to watch int kq; struct kevent ke; kq = kqueue(); fd = open(argv[1], O_RDONLY); EV_SET(&ke, fd,…
eradman
  • 1,996
  • 1
  • 17
  • 23
6
votes
2 answers

Haskell concurrency over kqueue

I wrote concurrent application and have caught the error: buildFdSets: file descriptor out of range I found out that it is the OS limit on the number of file descriptors in one process, in my FreeBSD it is 1024. It is the limit of select(). Also…
Anton
  • 2,535
  • 2
  • 25
  • 28
6
votes
1 answer

What exactly is kqueue's EV_RECEIPT for?

The kqueue mechanism has an event flag, EV_RECEIPT, which according to the linked man page: ... is useful for making bulk changes to a kqueue without draining any pending events. When passed as input, it forces EV_ERROR to …
davmac
  • 20,150
  • 1
  • 40
  • 68
6
votes
2 answers

Kqueue on regular files

Is kqueue (on OS X) useful for reading/writing regular files? I know that epoll is not useful for regular files on Linux, so I'm wondering if the same is true for kqueue. EDIT: I don't mean reading/writing files, obviously read() and write() are…
Matt Fichman
  • 5,458
  • 4
  • 39
  • 59
1
2 3
8 9