Skip to content

fasync_helper() and kill_fasync()

Purpose

The fasync API allows a driver to notify user space through SIGIO.

Driver Callback

static int mydev_fasync(int fd, struct file *file, int on)
{
    struct mydev_data *dev = file->private_data;

    return fasync_helper(fd, file, on, &dev->async_queue);
}

Event Notification

kill_fasync(&dev->async_queue, SIGIO, POLL_IN);

User-space Setup

User space typically needs to:

  1. Set the owner with F_SETOWN
  2. Enable O_ASYNC
  3. Install a SIGIO handler

Common Pitfalls

Warning

Signals are not a structured event queue. For complex event loops, bridging SIGIO into eventfd may be easier to integrate with epoll.