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
3
votes
1 answer

Difference in kqueue handling of fifos between Mac OS and FreeBSD?

I'm working on an application that uses fifos for IPC and uses an event-notification API (such as epoll or kqueue) to monitor the fifos for data to be read. The application expects that if the writer for a fifo terminates that the reader will…
80x25
  • 701
  • 5
  • 7
3
votes
1 answer

Can epoll or kqueue handle asynchronous additions of file descriptors to itself

If one thread (say X) is waiting on an epoll_wait() can another thread (say Y) makes a call to epoll_ctl() to register interest in file descriptor 9. Can the previous call to epoll_wait() in thread X return the file descriptor 9 added by thread Y?…
Curious
  • 20,870
  • 8
  • 61
  • 146
3
votes
1 answer

Use kqueue to determine hangup on the other side of the socket or exceptional state of the socket

I've read man 2 kqueue but have not found out how I can get notified about a socket hangup or exceptional condition of the socket without registering it with EVFILT_READ or EVFILT_WRITE. Apart from this it is not fully clear how kqueue signals…
Florian Mayer
  • 3,041
  • 24
  • 17
3
votes
3 answers

triggering kevent by force

I'm using kqueue for socket synchronization in OS X. I can register an event of interest like the following: struct kevent change; EV_SET(&change, connected_socket, EVFILT_READ, EV_ADD, 0, NULL, NULL); kevent(k_queue_, &change, 1, NULL, 0,…
Kay
  • 351
  • 1
  • 5
  • 17
3
votes
1 answer

How can I detect when a file is sent to trash using Kqueue?

I'm working with Kqueues on mac os x and I'm trying to monitor a folder so I used EVFILT_VNODE filter and I want to get a notification whenever a file is deleted , I tried NOTE_DELETE but it only detects when a file gets deleted through unlink()…
user3742053
  • 83
  • 1
  • 1
  • 10
3
votes
2 answers

What's the purpose of kqueue EV_ENABLE and EV_DISABLE

I'm trying to understand the use case for EV_DISABLE and EV_ENABLE in kqueue. int KQueue = kqueue(); struct kevent ev = { .ident = fd, .filter = EVFILT_READ, .flags = EV_ADD | EV_DISABLE, .udata = somePtr }; kevent(KQueue, &ev, 1, NULL, 0,…
vestol
  • 167
  • 7
3
votes
1 answer

using kqueue for EVFILT_USER

I have trouble to understand, how to use kqueue for user space events. I look for 2 use cases. Use case 1: Manual Reset event Use case 2: Auto Reset event I think I understand, how to use kqueue() and kevent(), yet I am unclear on how the events…
BitTickler
  • 10,905
  • 5
  • 32
  • 53
3
votes
1 answer

kqueue tracking file changes - chance of losing events while processing previous ones?

What I'm doing I'm implementing a python/kqueue-based (FreeBSD) solution to follow changes to a particular logfile, which when the KQ_NOTE_WRITE fflag is met, the change to the file is picked up and processed by another function within my python…
swisscheese
  • 321
  • 3
  • 12
2
votes
2 answers

kqueue() and O_NONBLOCK

If you use kqueue(), should you set O_NONBLOCK on your file descriptors? In other words, does kqueue() guarantee that the next I/O operation on a ready file descriptor will not block, regardless of whether O_NONBLOCK is set?
Matt Fichman
  • 5,458
  • 4
  • 39
  • 59
2
votes
2 answers

Efficient preforked server design with NBIO like epoll, kqueue using libevent

I am planning on writing a 'comet' server for 'streaming' data to clients. I have enhanced one in the past to take advantage of the multi-core CPUs but now I'm starting from scratch. I am planning to use epoll/kqueue or libevent to power the…
void_ptr
  • 472
  • 3
  • 9
2
votes
2 answers

Detect file creation or deletion under given path using python and kqueue on FreeBSD

Given /certain/path/ on a FreeBSD system, I would like python to use kqueue to detect if any files are created or deleted anywhere under that path. How would I do this?
David
  • 493
  • 7
  • 15
2
votes
2 answers

Reading updated files on the fly in Python

I'm writing two Python scripts that both parse files. One is a standard unix logfile and the other is a binary file. I'm trying to figure out the best way to monitor these so I can read data as soon as they're updated. Most of the solutions I've…
fbd39j
  • 35
  • 2
  • 4
2
votes
1 answer

Use python select kqueue on OSX to monitor file creation by external application

Typically the transcode of my 1 hr long audio recording sessions to an mp3 file takes twenty odd minutes. I want to use a python script to execute a series of python code when the OSX application garageband finishes writing that mp3 file. What are…
harijay
  • 11,303
  • 12
  • 38
  • 52
2
votes
2 answers

On iOS, how can an app determine if a file is no longer being written to by another process?

My question is very similar to this one: What is the optimal way to monitor changes in a directory with a kqueue()? but I'm not satisfied with the answer there. I have a kqueue setup to be notified when a file is copied to my app's Documents…
bosmacs
  • 7,341
  • 4
  • 31
  • 31
2
votes
0 answers

How to make libwebsockets use kqueue() system call internally instead of _poll()?

SO FAR: 1- I have a native application that uses libwebsocket server to communicate to a browser(websockets client). 2- I see a HIGH CPU usage(activity monitor indicates 100% usage in a 4 core mac machine- Yosemite(10.10.4)) when the app is…
1 2
3
8 9