codexplorer
codexplorer

Reputation: 551

How does Linux kernel interrupt the application?

First of all, I am a device driver guy. This is my first time to handle an user mode program. I used to have an interrupt service routine to response a hardware interrupt. In other word, the hardware uses interrupt service routine to notify the driver to service. I use ioctl to be a channel to communicate between the application and device driver now and poll it to wait the response. Are there other ways that a device driver can notify an application when it finishes some task? Any comments are welcome. Thanks,

Upvotes: 2

Views: 1434

Answers (3)

Sam Protsenko
Sam Protsenko

Reputation: 14743

There are several mechanisms for this. First approach: user-space application makes poll() or select() system call, waiting for some event from kernel. Second approach is to use Netlink sockets. There are also others like mmap() or signals. Google by kernel user-space IPC and you will see the whole list.

As for your case (drivers development), I'd say go with next approach. Create sysfs file in your driver, and do sysfs_notify() (and maybe wait_for_completion_interruptible_timeout() or something like that). In user-space do select() system call for your driver sysfs file. See how line discipline installed from user-space for example.

Upvotes: 5

synther
synther

Reputation: 336

There are plenty of kernel-userspace communication interfaces in addition to ioctl (signals, sockets, etc). Please, refer to Kernel Space - User Space Interfaces tutorial for detailed explanation.

Upvotes: 2

doron
doron

Reputation: 28872

Typically, the kernel never notifies an application unless the application requests the notification and is waiting for the notification. On unix systems, this will typically be done using the select or similar routines. One supplies select with a set of file descriptors and select will then wait until there is activity on one of the file descriptors at which time it returns.

Given that on unix all devices are files, you should be able to make use of this mechanism to wake an application when an interrupt comes in on some hardware device.

Upvotes: 4

Related Questions